Create activities manually?
peyloride opened this issue · comments
Hello,
First of all, thanks for the gem. I really appreciate your work. About my question, I'm designing some kind of announcement system and I want to create multiple activities. For example I tried to do following;
PublicActivity::Activity.create!(
trackable_id: 13,
trackable_type: 'Announcement',
key: 'shared.announcement',
recipient_id: 136130,
recipient_type: 'User'
)
But trackable and recipient fields set to nil (because of some callbacks?). As far as I understand, I need to do this;
PublicActivity::Activity.create!(
trackable: Announcement.find(13),
key: 'shared.announcement',
recipient: User.find(136130)
)
But this means 2 extra SQL request per activity. How can I solve this? I tried to look for documentation but didn't find an answer.
Thanks!
I haven't looked into why this happens, but you can always do this as a hack:
PublicActivity::Activity.create!(
trackable: Announcement.new(id: 13),
key: 'shared.announcement',
recipient: User.new(id: 136130)
)
Thanks! As an another workaround, I can make it via PublicActivity::Activity.new and save it.
@peyloride what kind of Rails version do you have? Activity has no callbacks so it's mostly likely Rails related
@pokonski Rails version '4.1.13', I do not have any callback about Public Activity, weird.
@peyloride did you solve thie issue?
I will close it as solved, if it still happens we can reopen :)