Remove complex methods from follow model. Create instance method followed_by? on followable model concern. Some code improvements.

This commit is contained in:
Senén Rodero Rodríguez
2017-07-19 21:50:37 +02:00
parent dec7d2d2b5
commit b7bce2e699
5 changed files with 16 additions and 31 deletions

View File

@@ -3,8 +3,7 @@ class FollowsController < ApplicationController
load_and_authorize_resource
def create
followable = find_followable
@follow = Follow.create(user: current_user, followable: followable)
@follow = Follow.create(user: current_user, followable: find_followable)
flash.now[:notice] = t("shared.followable.#{followable_translation_key(@follow.followable)}.create.notice_html")
render :refresh_follow_button
end
@@ -23,7 +22,7 @@ class FollowsController < ApplicationController
end
def followable_translation_key(followable)
followable.class.name.parameterize.gsub("-", "_")
followable.class.name.parameterize("_")
end
end