Retrospring/app/controllers/ajax/smile_controller.rb

78 lines
1.4 KiB
Ruby

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
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
end