public-activity / public_activity

Easy activity tracking for models - similar to Github's Public Activity

Home Page:https://github.com/pokonski/public_activity

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot access parameters from data

brenoperucchi opened this issue · 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"

I had to insert this to back to work again.

#activity.rb
serialize :parameters, Hash

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

public_activity (1.6.1)

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 thanks for the details, I'll inspect as this definitely shouldn't happen.

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'
commented

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...`

commented

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