1

I am having a problem when I deploy my project to Heroku. Running it in my localhost works fine and I but deployed gives me this error:

I am using the public_activity gem to get a feed of the last activity done in my app.

2020-06-22T18:00:31.055655+00:00 app[web.1]: [3e23fc99-a452-4cb4-900d-087df67a3f6b] ActionView::Template::Error (undefined method `with_indifferent_access' for "{}":String):
2020-06-22T18:00:31.055655+00:00 app[web.1]: [3e23fc99-a452-4cb4-900d-087df67a3f6b]     1: <% @activities.each do |activity| %>
2020-06-22T18:00:31.055656+00:00 app[web.1]: [3e23fc99-a452-4cb4-900d-087df67a3f6b]     2: <div class="activity">
2020-06-22T18:00:31.055656+00:00 app[web.1]: [3e23fc99-a452-4cb4-900d-087df67a3f6b]     3:     <%= activity.owner.name if activity.owner %>
2020-06-22T18:00:31.055656+00:00 app[web.1]: [3e23fc99-a452-4cb4-900d-087df67a3f6b]     4:     <%= render_activity activity %>
2020-06-22T18:00:31.055657+00:00 app[web.1]: [3e23fc99-a452-4cb4-900d-087df67a3f6b]     5: </div>
2020-06-22T18:00:31.055657+00:00 app[web.1]: [3e23fc99-a452-4cb4-900d-087df67a3f6b]     6: <% end %>
2020-06-22T18:00:31.055658+00:00 app[web.1]: [3e23fc99-a452-4cb4-900d-087df67a3f6b]   
2020-06-22T18:00:31.055658+00:00 app[web.1]: [3e23fc99-a452-4cb4-900d-087df67a3f6b] app/views/activities/index.html.erb:4
2020-06-22T18:00:31.055658+00:00 app[web.1]: [3e23fc99-a452-4cb4-900d-087df67a3f6b] app/views/activities/index.html.erb:1
2020-06-22T18:00:31.055671+00:00 app[web.1]: [3e23fc99-a452-4cb4-900d-087df67a3f6b] app/controllers/concerns/users/time_zone.rb:19:in `block in set_time_zone'
2020-06-22T18:00:31.055671+00:00 app[web.1]: [3e23fc99-a452-4cb4-900d-087df67a3f6b] app/controllers/concerns/users/time_zone.rb:19:in `set_time_zone'
2020-06-22T18:00:31.055672+00:00 app[web.1]: [3e23fc99-a452-4cb4-900d-087df67a3f6b] lib/jumpstart/lib/jumpstart/account_middleware.rb:30:in `call'
2020-06-22T18:00:31.056486+00:00 app[web.1]: I, [2020-06-22T18:00:31.056422 #4]  INFO -- : [3e23fc99-a452-4cb4-900d-087df67a3f6b] Processing by ErrorsController#internal_server_error as HTML
2020-06-22T18:00:31.057546+00:00 app[web.1]: I, [2020-06-22T18:00:31.057488 #4]  INFO -- : [3e23fc99-a452-4cb4-900d-087df67a3f6b]   Rendering errors/internal_server_error.html.erb within layouts/errors
2020-06-22T18:00:31.057825+00:00 app[web.1]: I, [2020-06-22T18:00:31.057762 #4]  INFO -- : [3e23fc99-a452-4cb4-900d-087df67a3f6b]   Rendered errors/internal_server_error.html.erb within layouts/errors (Duration: 0.2ms | Allocations: 42)
2020-06-22T18:00:31.058712+00:00 app[web.1]: I, [2020-06-22T18:00:31.058652 #4]  INFO -- : [3e23fc99-a452-4cb4-900d-087df67a3f6b]   Rendered shared/_favicons.html.erb (Duration: 0.0ms | Allocations: 6)
2020-06-22T18:00:31.058933+00:00 app[web.1]: I, [2020-06-22T18:00:31.058882 #4]  INFO -- : [3e23fc99-a452-4cb4-900d-087df67a3f6b] Completed 500 Internal Server Error in 2ms (Views: 1.6ms | ActiveRecord: 0.0ms | Allocations: 810)

The controller for activities I am using is this one:

class ActivitiesController < ApplicationController
  def index
    @activities = PublicActivity::Activity.order("created_at desc").where(recipient_id: current_account.id, recipient_type: "Account")
  end
end

Then I have these lines in the post and discussion controller after create, update, and destroy save:

@post.create_activity :create, owner: current_user, recipient: current_account

The code in app/views/index.html.erb

<% @activities.each do |activity| %>
<div class="activity">
    <%= activity.owner.name if activity.owner %>
    <%= render_activity activity %>
</div>
<% end %>

and app/controllers/concerns/users/time_zone.rb

module Users
  module TimeZone
    extend ActiveSupport::Concern

    included do
      helper_method :browser_time_zone
      around_action :set_time_zone
    end

    def browser_time_zone
      browser_tz = ActiveSupport::TimeZone.find_tzinfo(cookies[:browser_time_zone])
      ActiveSupport::TimeZone.all.find { |zone| zone.tzinfo == browser_tz } || Time.zone
    rescue TZInfo::UnknownTimezone, TZInfo::InvalidTimezoneIdentifier
      Time.zone
    end

    def set_time_zone
      if user_signed_in? && current_user.time_zone?
        Time.use_zone(current_user.time_zone) { yield }
      else
        yield
      end
    end
  end
end

The code from the render activity, public_activity gem gets it from the folder views/public_activity/post/_create.html.erb looks like this:

added a comm

<% if activity.trackable %>
<%= link_to activity.trackable.title, activity.trackable  %>
<% else %>
which has since been removed
<% end %>
4
  • 1
    Can you please add the content of app/views/activities/index.html.erb and app/controllers/concerns/users/time_zone.rb too. Commented Jun 22, 2020 at 21:02
  • I have added them know @ChristianBruckmayer Commented Jun 22, 2020 at 21:08
  • And the code from the render_activity helper please. Commented Jun 22, 2020 at 21:33
  • Added one template that renders. It doesn't have any code in helpers just gets the views from the public_activity folder in views. There I add folders for each model I want activities. Commented Jun 22, 2020 at 21:49

1 Answer 1

1

I found an answer (or at least a workaround) here:

https://github.com/chaps-io/public_activity/issues/345

When I checked, I saw that Heroku is saving parameters as the string '{}' instead of as an empty hash. Adding this line to the top of the loop fixed it for me:

<% @activities.each do |activity| %>
  <% activity.parameters = {} if activity.parameters == '{}' %>

Etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.