Retrospring/app/controllers/ajax/friend_controller.rb

40 lines
982 B
Ruby

class Ajax::FriendController < AjaxController
def create
params.require :screen_name
target_user = User.find_by_screen_name(params[:screen_name])
begin
current_user.follow target_user
rescue => e
Sentry.capture_exception(e)
@response[:status] = :fail
@response[:message] = I18n.t('messages.friend.create.fail')
return
end
@response[:status] = :okay
@response[:message] = I18n.t('messages.friend.create.okay')
@response[:success] = true
end
def destroy
params.require :screen_name
target_user = User.find_by_screen_name(params[:screen_name])
begin
current_user.unfollow target_user
rescue => e
Sentry.capture_exception(e)
@response[:status] = :fail
@response[:message] = I18n.t('messages.friend.destroy.fail')
return
end
@response[:status] = :okay
@response[:message] = I18n.t('messages.friend.destroy.okay')
@response[:success] = true
end
end