Files
nairobi/app/controllers/follows_controller.rb
Javi Martín d7ad1a769f Make sure users can only delete their own follows
Since we're defining abilities with cancancan and using
`load_and_authorize_resource`, we're also modifying the `create` action
for consistency.
2021-04-13 13:52:18 +02:00

27 lines
700 B
Ruby

class FollowsController < ApplicationController
before_action :authenticate_user!
load_and_authorize_resource
def create
@follow.save!
flash.now[:notice] = t("shared.followable.#{followable_translation_key(@follow.followable)}.create.notice")
render :refresh_follow_button
end
def destroy
@follow.destroy!
flash.now[:notice] = t("shared.followable.#{followable_translation_key(@follow.followable)}.destroy.notice")
render :refresh_follow_button
end
private
def follow_params
params.permit(:followable_type, :followable_id)
end
def followable_translation_key(followable)
followable.class.name.parameterize(separator: "_")
end
end