retrospring/app/controllers/ajax/subscription_controller.rb
2023-05-05 16:01:40 +02:00

17 lines
514 B
Ruby

class Ajax::SubscriptionController < AjaxController
before_action :authenticate_user!
def subscribe
params.require :answer
@response[:status] = :okay
result = Subscription.subscribe(current_user, Answer.find(params[:answer]))
@response[:success] = result.present?
end
def unsubscribe
params.require :answer
@response[:status] = :okay
result = Subscription.unsubscribe(current_user, Answer.find(params[:answer]))
@response[:success] = result&.destroyed? || false
end
end