Retrospring/app/controllers/ajax/smile_controller.rb

86 lines
1.8 KiB
Ruby
Raw Normal View History

class Ajax::SmileController < AjaxController
2014-11-30 11:31:22 -08:00
def create
params.require :id
answer = Answer.find(params[:id])
begin
current_user.smile answer
rescue Errors::Base => e
@response[:status] = e.code
@response[:message] = I18n.t(e.locale_tag)
return
rescue => e
2021-12-28 09:32:03 -08:00
Sentry.capture_exception(e)
@response[:status] = :fail
@response[:message] = t(".error")
2014-11-30 11:31:22 -08:00
return
end
@response[:status] = :okay
@response[:message] = t(".success")
@response[:success] = true
2014-11-30 11:31:22 -08:00
end
def destroy
params.require :id
answer = Answer.find(params[:id])
begin
current_user.unsmile answer
rescue => e
2021-12-28 09:32:03 -08:00
Sentry.capture_exception(e)
@response[:status] = :fail
@response[:message] = t(".error")
2014-11-30 11:31:22 -08:00
return
end
@response[:status] = :okay
@response[:message] = t(".success")
@response[:success] = true
2014-11-30 11:31:22 -08:00
end
def create_comment
params.require :id
comment = Comment.find(params[:id])
begin
current_user.smile comment
rescue Errors::Base => e
@response[:status] = e.code
@response[:message] = I18n.t(e.locale_tag)
return
rescue => e
2021-12-28 09:32:03 -08:00
Sentry.capture_exception(e)
@response[:status] = :fail
@response[:message] = t(".error")
return
end
@response[:status] = :okay
@response[:message] = t(".success")
@response[:success] = true
end
def destroy_comment
params.require :id
comment = Comment.find(params[:id])
begin
current_user.unsmile comment
rescue => e
2021-12-28 09:32:03 -08:00
Sentry.capture_exception(e)
@response[:status] = :fail
@response[:message] = t(".error")
return
end
@response[:status] = :okay
@response[:message] = t(".success")
@response[:success] = true
end
2014-11-30 11:31:22 -08:00
end