Module: Horde::Actions::FavoriteMethods::ActorMethods

Extended by:
ActiveSupport::Concern
Defined in:
lib/horde/actions/favorite.rb

Overview

methods for user, usually User class in your app.

Instance Method Summary collapse

Instance Method Details

#favorite(target, options = {}) ⇒ Object

user favorite something.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/horde/actions/favorite.rb', line 25

def favorite(target, options = {})
  pks  = {:actor_id => self.id, 
          :target_id => target.id,
          :target_type => target.class.name
         }.merge(options)
  fav = ::Horde::Favorite.where(pks).first
  if fav
    # do nothing
  else
    params = pks.merge(options)
    fav = ::Horde::Favorite.create(params)
  end

  target.run_hook(:after_favorite, fav)

  fav
end