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

prepare_parameters raises exception when parameters nil

tillcarlos opened this issue · comments

Hey guys. First: great work! This is exactly the gem I was searching for.

On my dev+production machine sometimes activities get created with parameters being nil.

Then this code fails

    def prepare_parameters(params)
      @prepared_params ||= self.parameters.with_indifferent_access.merge(params)
    end

with_indifferent_access called on nil object.

I'm fixing it in the view with this:

<% @activities.each do |activity| %>
  <% activity.parameters ||= {} %>
  <%= render_activities(activity) %>
<% end %>

But it's weird that it's necessary. Maybe because I changed my migration to t.json "parameters" ? Default was text, but that crashed on my production machine (a vanilla dokku install... I did not check why text did not work, but json worked. If it's relevant I can investigate).

Wouldn't it make sense to just put in the default? Or change that method to always hand out at least empty hash? {}

Hi, Experience the same Error. I tried this workaround. But I still get an error in my production environment on Heroku. (it works fine on my local server)

Any ideas on how I can resolve this? Here's what I get back from my Heroku Logs.

[9972b504-118f-45f9-Completed 500 Internal Server Error in 128ms (ActiveRecord: 36.2ms | Allocations: 14844)

ActionView::Template::Error (undefined method `with_indifferent_access' for "{}":String):
<div class="grid md:grid-cols-12 md:mr-12 my-5 md:ml-24">
<% @activities.each do |activity| %>
 <% activity.parameters ||= {} %>
<%= render_activities(activity) %>
<% end %>
</div>