How can i set include_root_in_json to false for all my RoR models?
I've tried to set ActiveModel::Base.include_root_in_json = false inside application.rb, but it has no effect.
Model.to_json method is used to returns a JSON string representing the model and i have used self.include_root_in_json = false in a model itself.
But for the whole application you can try setting ActiveModel::Base.include_root_in_json = false in an initializer.[edit This does not work.]
[edit] ActiveRecord::Base.include_root_in_json = true try adding this line to config/environment.rb file.
I'm not sure if this is true for the later versions of rails but for me (running 2.3.5 atm) there was already a declaration for this setting in /config/initializers/new_rails_defaults.rb where it was set to:
ActiveRecord::Base.include_root_in_json = true
So if you try to set this setting in another place then it might be overridden.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With