Setting properties on ActiveModel::Base from an initializer
Content of initializers/rails_defaults.rb
ActiveModel::Base.include_root_in_json = false
The error I get on startup:
NameError: uninitialized constant ActiveModel::Base
Anyone know of a remedy?
I'm using 开发者_运维技巧rails 3.1.RC4.
Rails 2.x? Change ActiveModel
to ActiveRecord
, and look in initializers/new_rails_defaults.rb
for the setting.
See:
http://apidock.com/rails/ActiveRecord/Serialization/to_json
Rails 3? Looks like for now you set it in the model directly instead:
class MyModel < ActiveRecord::Base
self.include_root_in_json = true
end
Edit:
You may also want to look at this:
Rails 3.1 include_root_in_json
精彩评论