diff --git a/app/helpers/action_tracker_helper.rb b/app/helpers/action_tracker_helper.rb index 196d9ad..e6f8a66 100644 --- a/app/helpers/action_tracker_helper.rb +++ b/app/helpers/action_tracker_helper.rb @@ -85,4 +85,10 @@ module ActionTrackerHelper } end + def favorite_enterprise_description ta + _('favorited enterprise %{title}') % { + title: link_to(truncate(ta.get_enterprise_name), ta.get_enterprise_url), + } + end + end diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 5cc43f6..7024c57 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -23,7 +23,7 @@ class Enterprise < Organization has_many :production_costs, :as => :owner has_many :favorite_enterprise_people - has_many :fans, through: :favorite_enterprise_people, source: :person + has_many :fans, source: :person, through: :favorite_enterprise_people def product_categories ProductCategory.by_enterprise(self) diff --git a/app/models/favorite_enterprise_person.rb b/app/models/favorite_enterprise_person.rb index f46cbe3..764dc2a 100644 --- a/app/models/favorite_enterprise_person.rb +++ b/app/models/favorite_enterprise_person.rb @@ -1,8 +1,23 @@ class FavoriteEnterprisePerson < ActiveRecord::Base - self.table_name = :favorite_enteprises_people + attr_accessible :person, :enterprise + + track_actions :favorite_enterprise, :after_create, keep_params: [:enterprise_name, :enterprise_url], if: proc{ |f| f.is_trackable? } belongs_to :enterprise belongs_to :person + protected + + def is_trackable? + self.enterprise.public? + end + + def enterprise_name + self.enterprise.short_name(nil) + end + def enterprise_url + self.enterprise.url + end + end diff --git a/app/models/person.rb b/app/models/person.rb index 63b79e2..c1e8378 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -81,6 +81,9 @@ roles] } has_many :scraps_sent, :class_name => 'Scrap', :foreign_key => :sender_id, :dependent => :destroy + has_many :favorite_enterprise_people + has_many :favorite_enterprises, source: :enterprise, through: :favorite_enterprise_people + has_and_belongs_to_many :acepted_forums, :class_name => 'Forum', :join_table => 'terms_forum_people' has_and_belongs_to_many :articles_with_access, :class_name => 'Article', :join_table => 'article_privacy_exceptions' @@ -315,8 +318,6 @@ roles] } ] end - has_and_belongs_to_many :favorite_enterprises, :class_name => 'Enterprise', :join_table => 'favorite_enteprises_people' - def email_domain user && user.email_domain || environment.default_hostname(true) end diff --git a/app/models/profile.rb b/app/models/profile.rb index 9946e84..ca0ddf5 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -744,7 +744,11 @@ private :generate_url, :url_options include ActionView::Helpers::TextHelper def short_name(chars = 40) if self[:nickname].blank? - truncate self.name, :length => chars, :omission => '...' + if chars + truncate self.name, length: chars, omission: '...' + else + self.name + end else self[:nickname] end diff --git a/app/views/profile/_favorite_enterprise.html.erb b/app/views/profile/_favorite_enterprise.html.erb new file mode 100644 index 0000000..16ae381 --- /dev/null +++ b/app/views/profile/_favorite_enterprise.html.erb @@ -0,0 +1,15 @@ +
+ <%= link_to activity.user.short_name(nil), activity.user.url %> <%= describe activity %> +
+<%= time_ago_as_sentence activity.created_at %>
+ +