Retrospring/app/controllers/ajax/smile_controller.rb

85 lines
1.8 KiB
Ruby
Raw Normal View History

2014-11-30 11:31:22 -08:00
class Ajax::SmileController < 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 11:31:22 -08:00
def create
params.require :id
answer = Answer.find(params[:id])
begin
current_user.smile answer
rescue
@status = :fail
2015-06-07 09:24:01 -07:00
@message = I18n.t('messages.smile.create.fail')
2014-11-30 11:31:22 -08:00
@success = false
return
end
@status = :okay
2015-06-07 09:24:01 -07:00
@message = I18n.t('messages.smile.create.okay')
2014-11-30 11:31:22 -08:00
@success = true
end
def destroy
params.require :id
answer = Answer.find(params[:id])
begin
current_user.unsmile answer
rescue
@status = :fail
2015-06-07 09:24:01 -07:00
@message = I18n.t('messages.smile.destroy.fail')
2014-11-30 11:31:22 -08:00
@success = false
return
end
@status = :okay
2015-06-07 09:24:01 -07:00
@message = I18n.t('messages.smile.destroy.okay')
2014-11-30 11:31:22 -08:00
@success = true
end
def create_comment
params.require :id
comment = Comment.find(params[:id])
begin
current_user.smile_comment comment
rescue
@status = :fail
2015-06-07 09:24:01 -07:00
@message = I18n.t('messages.smile.create_comment.fail')
@success = false
return
end
@status = :okay
2015-06-07 09:24:01 -07:00
@message = I18n.t('messages.smile.create_comment.okay')
@success = true
end
def destroy_comment
params.require :id
comment = Comment.find(params[:id])
begin
current_user.unsmile_comment comment
rescue
@status = :fail
2015-06-07 09:24:01 -07:00
@message = I18n.t('messages.smile.destroy_comment.fail')
@success = false
return
end
@status = :okay
2015-06-07 09:24:01 -07:00
@message = I18n.t('messages.smile.destroy_comment.okay')
@success = true
end
2014-11-30 11:31:22 -08:00
end