Retrospring/app/controllers/ajax/friend_controller.rb

47 lines
1.1 KiB
Ruby
Raw Normal View History

2014-11-30 05:45:32 -08:00
class Ajax::FriendController < ApplicationController
2015-05-08 16:31:31 -07:00
rescue_from(ActionController::ParameterMissing) do |param_miss_ex|
@status = :parameter_error
2015-06-07 09:24:01 -07:00
@message = I18n.t('messages.parameter_error', parameter: param_miss_ex.param.capitalize)
2015-05-08 16:31:31 -07:00
@success = false
render partial: "ajax/shared/status"
end
2014-11-30 05:45:32 -08:00
def create
2014-11-30 06:13:37 -08:00
params.require :screen_name
target_user = User.find_by_screen_name(params[:screen_name])
begin
current_user.follow target_user
rescue
@status = :fail
2015-06-07 09:24:01 -07:00
@message = I18n.t('messages.friend.create.fail')
2014-11-30 06:13:37 -08:00
@success = false
return
end
2014-11-30 05:45:32 -08:00
@status = :okay
2015-06-07 09:24:01 -07:00
@message = I18n.t('messages.friend.create.okay')
2014-11-30 05:45:32 -08:00
@success = true
end
def destroy
2014-11-30 06:13:37 -08:00
params.require :screen_name
target_user = User.find_by_screen_name(params[:screen_name])
begin
current_user.unfollow target_user
rescue
@status = :fail
2015-06-07 09:24:01 -07:00
@message = I18n.t('messages.friend.destroy.fail')
2014-11-30 06:13:37 -08:00
@success = false
return
end
2014-11-30 05:45:32 -08:00
@status = :okay
2015-06-07 09:24:01 -07:00
@message = I18n.t('messages.friend.destroy.okay')
2014-11-30 05:45:32 -08:00
@success = true
end
end