ROR Error: undefined method `include_root_in_json=’ …
Background
Upon continuing a Ruby on Rails project after a few months delay, Aptana Studio’s RadRails editor installed some updates. I suspect something that changed in Rails itself (GEM update) caused the error I received.
Error Message
undefined method `include_root_in_json=’ for ActiveRecord::Base:Class (NoMethodError)
Solution
To fix this error rename the config/initializers/new_rails_defaults.rb to config/initializers/new_rails_defaults.rb.bak.
It appears that the old code placed in these files no longer works with ROR 2.0.2.
# These settings change the behavior of Rails 2 apps and will be defaults
# for Rails 3. You can remove this initializer when Rails 3 is released.# Include Active Record class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = true# Store the full class name (including module namespace) in STI type column.
ActiveRecord::Base.store_full_sti_class = true# Use ISO 8601 format for JSON serialized times and dates.
ActiveSupport.use_standard_json_time_format = true# Don’t escape HTML entities in JSON, leave that for the #json_escape helper.
# if you’re including raw json in an HTML page.
ActiveSupport.escape_html_entities_in_json = false
The file now created in a new project appears as follows:
# These settings change the behavior of Rails 2 apps and will be defaults
# for Rails 3. You can remove this initializer when Rails 3 is released.if defined?(ActiveRecord)
# Include Active Record class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = true# Store the full class name (including module namespace) in STI type column.
ActiveRecord::Base.store_full_sti_class = true
end# Use ISO 8601 format for JSON serialized times and dates.
ActiveSupport.use_standard_json_time_format = true# Don’t escape HTML entities in JSON, leave that for the #json_escape helper.
# if you’re including raw json in an HTML page.
ActiveSupport.escape_html_entities_in_json = false
Footnotes
See http://www.hostingrails.com/1461/dbmigrate-undefined-method-include_root_in_json for more help with this error.
