Created
November 16, 2013 21:46
-
-
Save uberllama/7505774 to your computer and use it in GitHub Desktop.
Concern version of https://gist.github.com/uberllama/7505705
This file contains hidden or 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
# app/models/comment.rb | |
class Comment < ActiveRecord::Base | |
include TrackableObserver | |
belongs_to :user | |
has_many :activities, as: :trackable | |
end | |
# app/models/like.rb | |
class Like < ActiveRecord::Base | |
include TrackableObserver | |
belongs_to :user | |
has_many :activities, as: :trackable | |
end | |
# app/models/activity.rb | |
class Activity < ActiveRecord::Base | |
belongs_to :user | |
belongs_to :trackable, polymorphic: true | |
end | |
# /app/models/concerns/trackable_observer.rb | |
module TrackableObserver | |
extend ActiveSupport::Concern | |
included do | |
after_create :create_activity | |
end | |
private | |
def create_activity | |
activities.create(user_id: user_id) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment