Notes posted by felixmcallister

RSS feed
September 1, 2008 - (>= v2.1.0)
5 thanks


From Rails 2.1 onwards, the variable


affects how the JSON is generated. If this is true (default), then the JSON isn’t like the one above. Instead you’ll get:

konata = User.find(1)
# => { "user": { "id": 1, "name": "Konata Izumi", "age": 16,
      "created_at": "2006/08/01", "awesome": true}}

(Note the model name is included as a root of the JSON object)

For Rails 2.1 generated projects, you’ll see this in the config/initializers/new_rails_defaults.rb file. You’ll need to set the value to false if you want the old behaviour.

ActiveRecord::Base.include_root_in_json = false