When I did this earlier , I dealt with it by having a denormalized model UserActivityor similar with a polymorphic association belongs_towith ActivitySource- which can be any types of content that you want to display (messages, comments, voices, preferences, whatever ...).
, , , Observer, UserActivity .
, , UserActivity created_at , activity_source . smarts , -, .
. - ...
user_activity.rb:
class UserActivity < ActiveRecord::Base
belongs_to :activity_source, :polymorphic => true
end
comment.rb(post/whatever)
class Comment < ActiveRecord::Base
end
activity_source_observer.rb
class ActivitySourceObserver < ActiveRecord::Observer
observe :comment, :post
def after_create(activity_source)
UserActivity.create!(
:user => activity_source.user,
:activity_source_id => activity_source.id,
:activity_source_type => activity_source.class.to_s,
:created_at => activity_source.created_at,
:updated_at => activity_source.updated_at)
end
def before_destroy(activity_source)
UserActivity.destroy_all(:activity_source_id => activity_source.id)
end
end