Simplify passing parameters in FollowsController

This commit is contained in:
Javi Martín
2023-07-01 21:39:41 +02:00
parent 9d74f06d24
commit 88f499d114

View File

@@ -4,13 +4,13 @@ class FollowsController < ApplicationController
def create
@follow.save!
flash.now[:notice] = t("shared.followable.#{followable_translation_key(@follow.followable)}.create.notice")
flash.now[:notice] = t("shared.followable.#{followable_translation_key(@follow)}.create.notice")
render :refresh_follow_button
end
def destroy
@follow.destroy!
flash.now[:notice] = t("shared.followable.#{followable_translation_key(@follow.followable)}.destroy.notice")
flash.now[:notice] = t("shared.followable.#{followable_translation_key(@follow)}.destroy.notice")
render :refresh_follow_button
end
@@ -24,7 +24,7 @@ class FollowsController < ApplicationController
[:followable_type, :followable_id]
end
def followable_translation_key(followable)
followable.class.name.parameterize(separator: "_")
def followable_translation_key(follow)
follow.followable.class.name.parameterize(separator: "_")
end
end