class FollowsController < ApplicationController before_action :authenticate_user! load_and_authorize_resource def create @follow = current_user.follows.create!(follow_params) flash.now[:notice] = t("shared.followable.#{followable_translation_key(@follow.followable)}.create.notice") render :refresh_follow_button end def destroy @follow = Follow.find(params[:id]) @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