cirandas.net

ref: master

app/models/favorite_enterprise_person.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class FavoriteEnterprisePerson < ApplicationRecord

  attr_accessible :person, :enterprise

  track_actions :favorite_enterprise, :after_create, keep_params: [:enterprise_name, :enterprise_url], if: proc{ |f| f.notifiable? }

  belongs_to :enterprise
  belongs_to :person

  after_create do |favorite|
    favorite.person.follow(favorite.enterprise, Circle.find_or_create_by(:person => favorite.person, :name =>_('favorites'), :profile_type => 'Enterprise'))
  end

  protected

  def notifiable?
    self.enterprise.public?
  end

  def enterprise_name
    self.enterprise.short_name(nil)
  end
  def enterprise_url
    self.enterprise.url
  end

end