-
-
Save kivanio/8e57420f8cd239ff3625 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Activity < ActiveRecord::Base | |
# columns: | |
# * entity_id | |
# * entity_type | |
# * action | |
# * created_at | |
belongs_to :entity, :polymorphic => true | |
end | |
class User | |
has_many :activities, :as => :entity | |
after_save :log_activity | |
private | |
def log_activity | |
activities.create(:action => 'create') | |
end | |
end | |
class Post | |
has_many :activities, :as => :entity | |
private | |
def log_activity | |
activities.create(:action => 'create') | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Activity < ActiveRecord::Base | |
# columns: | |
# * entity_id | |
# * entity_type | |
# * action | |
# * created_at | |
belongs_to :entity, :polymorphic => true | |
end | |
class User | |
has_many :activities, :as => :entity | |
end | |
class Post | |
has_many :activities, :as => :entity | |
end | |
class LoggableObserver < ActiveRecord::Observer | |
observe :user, :post | |
def after_save(loggable) | |
loggable.activities.create(:action => 'create') | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Loggable | |
extend ActiveSupport::Concern | |
included do | |
after_save :log_activity | |
end | |
private | |
def log_activity | |
activities.create(:action => 'create') | |
end | |
end | |
class Activity < ActiveRecord::Base | |
# columns: | |
# * entity_id | |
# * entity_type | |
# * action | |
# * created_at | |
belongs_to :entity, :polymorphic => true | |
end | |
class User | |
include Loggable | |
has_many :activities, :as => :entity | |
end | |
class Post | |
include Loggable | |
has_many :activities, :as => :entity | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Loggable | |
extend ActiveSupport::Concern | |
included do | |
after_save :log_activity | |
has_many :activities, :as => :entity | |
end | |
private | |
def log_activity | |
activities.create(:action => 'create') | |
end | |
end | |
class Activity < ActiveRecord::Base | |
# columns: | |
# * entity_id | |
# * entity_type | |
# * action | |
# * created_at | |
belongs_to :entity, :polymorphic => true | |
end | |
class User | |
include Loggable | |
end | |
class Post | |
include Loggable | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment