phenomenon
phenomenon

Reputation: 61

Rails gem - Public Activity for earlier posts

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.

Upvotes: 1

Views: 68

Answers (1)

Linus Oleander
Linus Oleander

Reputation: 18157

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

Upvotes: 1

Related Questions