1

The gem does not recognize earlier post which were created before the gem was added. It only started working, when fresh posts were created. Why was that?

And, how to have those earlier posts get covered by public_activity

Thanks.
Gem setup according to author site.

phenomenon
  • 61
  • 8
  • 1
    At first glance, it looks like you should write a migration file which adds `activities` to the already existing posts. See http://www.rubydoc.info/gems/public_activity/PublicActivity/Common:create_activity – wiesion Sep 30 '15 at 20:14

1 Answers1

1

You've to create the old activities manually using create_activity method. I created a rake task for this.

task public_activity_migration: :environment do
  User.find_each do |user|
    [:comments, :friends].each do |relation|
      user.send(relation).find_each do |obj|
        obj.create_activity :create, owner: user, created_at: obj.created_at
        print "."
      end
    end
  end
end

The code above will create activities for the comment and friend model. If you're not using strong params you also need to allow the created_at attribute to be set on the PublicActivity::Activity model. This can be done by adding the following code before running your task.

class PublicActivity::Activity
  attr_accessible :created_at
end
Linus Oleander
  • 17,746
  • 15
  • 69
  • 102