public_activity icon indicating copy to clipboard operation
public_activity copied to clipboard

Cannot access parameters from data

Open brenoperucchi opened this issue 5 years ago • 8 comments

I cannot understand why it's happening now. I don't now if was happen because I recently upgrade to Rails 5. But suddenly I don't get access to object.parameters of activity

       tracked :owner      =>  proc {|controller, model| User.current.userable},
          :recipient  =>  proc {|controller, model| model.unit},
          :params => {:comment => "test" },
          :on => {
                   :update => proc {|model, controller| !model.comment.blank? }
                 }
>> activity.parameters[:comment]
!! #<TypeError: no implicit conversion of Symbol into Integer>
>> activity.parameters
=> "---\n:comment: test\n"

brenoperucchi avatar Jul 25 '18 22:07 brenoperucchi

I had to insert this to back to work again.

#activity.rb
serialize :parameters, Hash

brenoperucchi avatar Jul 25 '18 23:07 brenoperucchi

@brenoperucchi what version were you using? 1.6.0 fixes your issue I believe.

pokonski avatar Jul 30 '18 09:07 pokonski

public_activity (1.6.1)

brenoperucchi avatar Aug 02 '18 20:08 brenoperucchi

Same in 1.6.2. I had to create a file and write the following to make it work:

module ::PublicActivity
  class Activity
    serialize :parameters, Hash
  end
end

Edit: when you run this on Travis (you start from an empty database), you'll get the following messages which weren't happening in Rails 4:

[WARN] table PublicActivity::ORM::ActiveRecord::Activity doesn't exist. Skipping PublicActivity::Activity#parameters's serialization

This might be related.

mssola avatar Oct 18 '18 10:10 mssola

@mssola thanks for the details, I'll inspect as this definitely shouldn't happen.

pokonski avatar Oct 19 '18 10:10 pokonski

I noticed that activities generated in response to seed data being created are stored in the db parameters column with traditional hash syntax, e.g.:

{:new_end_on=>"2019-07-17"}`

parameters for activities created during normal app usage and from console are stored like this:

---
:new_end_on: '2019-07-17'

I didn't even notice this until now because we had upgraded from Postgres 10 to Postgres 11 and it seems Postgres 11 barfs when trying to read/parse the traditional hash syntax (where Postgres 10/Active Record was able to parse both syntaxes w/out problems) with this error :

TypeError: no implicit conversion of Symbol into Integer

Also when deploying a review app on Heroku:

[WARN] table PublicActivity::ORM::ActiveRecord::Activity doesn't exist. Skipping PublicActivity::Activity#parameters's serialization

Following the above suggestions, I added serialize :parameters, Hash my PublicActivity module and the seed generated activity parameters data is now stored in the seemingly correct format:

module PublicActivity
  class Activity < inherit_orm('Activity')
    serialize :parameters, Hash
    ...
  end
end
---
:new_end_on: '2019-07-17'

micahlisonbee avatar Apr 18 '19 17:04 micahlisonbee

Any movement on this? I couldn't get the workaround (adding serialize :parameters, Hash) to work in 1.6.3 for some reason. I tried adding it directly to gems/2.4.0/gems/public_activity-1.6.3/lib/public_activity/activity.rb and I created a shim in config/initializers and added

module PublicActivity
  class Activity
    serialize :parameters, Hash
  end
end

But, I'm still getting undefined local variable or method parameters' for Class...`

kernelsmith avatar Jul 15 '19 18:07 kernelsmith

Also, I wanted to point out that it did work as of aff5b50ff474c9434e619c0fb0f8daa6acf47655 but that's right before you switched to inheriting from inherit_orm('Activity')

kernelsmith avatar Jul 15 '19 18:07 kernelsmith