Retrospring/app/controllers/ajax/smile_controller.rb

40 lines
744 B
Ruby
Raw Normal View History

2014-11-30 11:31:22 -08:00
class Ajax::SmileController < ApplicationController
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
end