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
|
2015-05-03 18:39:41 -07:00
|
|
|
|
|
|
|
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')
|
2015-05-03 18:39:41 -07:00
|
|
|
@success = false
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
@status = :okay
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.smile.create_comment.okay')
|
2015-05-03 18:39:41 -07:00
|
|
|
@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')
|
2015-05-03 18:39:41 -07:00
|
|
|
@success = false
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
@status = :okay
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.smile.destroy_comment.okay')
|
2015-05-03 18:39:41 -07:00
|
|
|
@success = true
|
|
|
|
end
|
2014-11-30 11:31:22 -08:00
|
|
|
end
|