Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I got this Error only on Heorku even Dev and Prod env is perfect ton local #350

Open
ronakabhattrz opened this issue Jun 8, 2020 · 9 comments
Assignees

Comments

@ronakabhattrz
Copy link

2020-06-08T07:12:17.134358+00:00 app[web.1]: [3db8f80c-1c97-46c3-bf39-9641607f049b] ActionView::Template::Error (undefined method `with_indifferent_access' for "{}":String):
2020-06-08T07:12:17.134359+00:00 app[web.1]: [3db8f80c-1c97-46c3-bf39-9641607f049b]     1: <%= render_activity(@activities, user: @user) %>

Thank :)

@tmyengstrom
Copy link

I get the same Error in Production (Heroku) did you manage to find a solution to this?

@ur5us
Copy link
Collaborator

ur5us commented May 15, 2022

@ronakabhattrz @tmyengstrom Do either of you have a code snippet or even better demo app to reproduce the issue?

@ur5us ur5us self-assigned this May 15, 2022
@maxsz
Copy link

maxsz commented Apr 19, 2023

Here is a workaround we're currently using:

config/initializers/public_activity.rb

require "public_activity"

module PublicActivityExtensions
  module PublicActivity
    module FieldAccess
      def parameters
        p = read_attribute(:parameters)
        p = ActiveSupport::JSON.decode(p) if p.is_a?(String)
        p
      end
    end
  end
end

PublicActivity::Activity.class_eval do
  include PublicActivityExtensions::PublicActivity::FieldAccess
end

@ronakabhattrz
Copy link
Author

Thanks @maxsz :)

@ur5us
Copy link
Collaborator

ur5us commented Apr 21, 2023

@ronakabhattrz @maxsz I’d still like to replicate and resolve this. I, too, have 2 apps deployed on Heroku but neither of those exhibit this particular error. So if either of you can provide more details that would be much appreciated.

@maxsz
Copy link

maxsz commented Apr 24, 2023

@ronakabhattrz @maxsz I’d still like to replicate and resolve this. I, too, have 2 apps deployed on Heroku but neither of those exhibit this particular error. So if either of you can provide more details that would be much appreciated.

I think this only happens if the column is not json(b) so that this code

serialize :parameters, Hash unless [:json, :jsonb, :hstore].include?(columns_hash['parameters'].type)
won't serialize it as a Hash. Then when rendering it always expects a Hash:
@prepared_params ||= self.parameters.with_indifferent_access.merge(params)

@AdManteza
Copy link

i am having the same issue

@ur5us
Copy link
Collaborator

ur5us commented Jul 7, 2023

@AdManteza What’s the database’s type for the parameter column?

@ur5us
Copy link
Collaborator

ur5us commented Jul 7, 2023

@maxsz Thanks for your input. I’ll double check that though I’m fairly certain that

serialize :parameters, Hash unless [:json, :jsonb, :hstore].include?(columns_hash['parameters'].type)
is the way it is because Rails should automatically serialize back and force if the database column type is of json, jsonb or hstore. I have a suspicion that the issue is caused by a null value instead.

@ur5us ur5us reopened this Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants