diff --git a/app/controllers/follows_controller.rb b/app/controllers/follows_controller.rb index 32fea6813..9cec999fa 100644 --- a/app/controllers/follows_controller.rb +++ b/app/controllers/follows_controller.rb @@ -18,11 +18,6 @@ class FollowsController < ApplicationController private def find_followable - params.each do |name, value| - if name =~ /(.+)_id$/ - return $1.classify.constantize.find(value) - end - end - nil + params[:followable_type].constantize.find(params[:followable_id]) end end diff --git a/app/helpers/follows_helper.rb b/app/helpers/follows_helper.rb index 19c8f9ca6..0ba6a8862 100644 --- a/app/helpers/follows_helper.rb +++ b/app/helpers/follows_helper.rb @@ -8,17 +8,21 @@ module FollowsHelper current_user && followed?(followable) end - def follow_entity_text(entity) + def follow_entity_text(followable) + entity = followable.class.name.gsub('::', '/').downcase t('shared.follow_entity', entity: t("activerecord.models.#{entity}.one").downcase) end - def unfollow_entity_text(entity) + def unfollow_entity_text(followable) + entity = followable.class.name.gsub('::', '/').downcase t('shared.unfollow_entity', entity: t("activerecord.models.#{entity}.one").downcase) end def entity_name(followable) - followable.class.name.downcase + entity_name = followable.class.name.split('::').last + entity_name.downcase end + private def followed?(followable) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 5fcf2e882..1cb3733a6 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -6,6 +6,7 @@ class Budget include Taggable include Searchable include Reclassification + include Followable acts_as_votable acts_as_paranoid column: :hidden_at diff --git a/app/models/follow.rb b/app/models/follow.rb index 571635b15..ee44cac96 100644 --- a/app/models/follow.rb +++ b/app/models/follow.rb @@ -13,17 +13,6 @@ class Follow < ActiveRecord::Base followable_id: followable.id) end) - # def self.follow(user, followable) - # return false if interested?(user, followable) - # create(user: user, followable: followable) - # end - # - # def self.unfollow(user, followable) - # interests = by_user_and_followable(user, followable) - # return false if interests.empty? - # interests.destroy_all - # end - # def self.followed?(user, followable) return false unless user !! by_user_and_followable(user, followable).try(:first) diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb index 42a8b9f26..b26db7263 100644 --- a/app/views/budgets/investments/_investment_show.html.erb +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -13,6 +13,10 @@ <%= l investment.created_at.to_date %>  •  <%= investment.heading.name %> +  •  + + <%= render 'follows/followable_button', followable: investment %> +
diff --git a/app/views/follows/_followable_button.html.erb b/app/views/follows/_followable_button.html.erb index 2f838448e..3eefc774c 100644 --- a/app/views/follows/_followable_button.html.erb +++ b/app/views/follows/_followable_button.html.erb @@ -1,20 +1,21 @@ +<% entity = entity_name(followable) %> <% if show_follow_action? followable %> - + <%= t('shared.follow') %> -