Retrospring/app/controllers/ajax/subscription_controller.rb

26 lines
838 B
Ruby
Raw Normal View History

2015-04-20 18:12:11 -07:00
class Ajax::SubscriptionController < ApplicationController
before_filter :authenticate_user!
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
2015-04-20 18:12:11 -07:00
def subscribe
params.require :answer
@status = 418
2015-06-07 09:24:01 -07:00
@message = I18n.t('messages.subscription.torpedo')
2015-04-20 18:12:11 -07:00
state = Subscription.subscribe(current_user, Answer.find(params[:answer])).nil?
@success = state == false
end
def unsubscribe
params.require :answer
@status = 418
2015-06-07 09:24:01 -07:00
@message = I18n.t('messages.subscription.torpedo')
2015-04-20 18:12:11 -07:00
state = Subscription.unsubscribe(current_user, Answer.find(params[:answer])).nil?
@success = state == false
end
end