Retrospring/app/controllers/ajax/smile_controller.rb

85 lines
1.7 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
@message = "#{param_miss_ex.param.capitalize} is required"
@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
@message = "You have already smiled that answer."
@success = false
return
end
@status = :okay
@message = "Successfully smiled answer."
@success = true
end
def destroy
params.require :id
answer = Answer.find(params[:id])
begin
current_user.unsmile answer
rescue
@status = :fail
@message = "You have not smiled that answer."
@success = false
return
end
@status = :okay
@message = "Successfully unsmiled answer."
@success = true
end
def create_comment
params.require :id
comment = Comment.find(params[:id])
begin
current_user.smile_comment comment
rescue
@status = :fail
@message = "You have already smiled that comment."
@success = false
return
end
@status = :okay
@message = "Successfully smiled comment."
@success = true
end
def destroy_comment
params.require :id
comment = Comment.find(params[:id])
begin
current_user.unsmile_comment comment
rescue
@status = :fail
@message = "You have not smiled that comment."
@success = false
return
end
@status = :okay
@message = "Successfully unsmiled comment."
@success = true
end
2014-11-30 11:31:22 -08:00
end