Rails 3.1 include_root_in_json

前端 未结 3 1821
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 06:36

ActiveRecord::Base.include_root_in_json = true doesn\'t seem to be working in rails 3.10.rc4 and I don\'t see it in the docs.

Since the root element is

3条回答
  •  既然无缘
    2020-12-03 06:52

    It turns out that Rails 3.1 just creates this json config file for you. I didn't know this file was here so my file in initializers was ignored.

    In Ryan's answer above does override this setting.

    config/initializers/wrap_parameters.rb

    # Be sure to restart your server when you modify this file.
    #
    # This file contains settings for ActionController::ParamsWrapper which
    # is enabled by default.
    
    # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
    ActionController::Base.wrap_parameters :format => [:json]
    
    # Disable root element in JSON by default.
    if defined?(ActiveRecord)
      ActiveRecord::Base.include_root_in_json = false
    end
    

提交回复
热议问题