Skip to content

Commit

Permalink
Use lazy load hooks to set parameter wrapping configuration. This mea…
Browse files Browse the repository at this point in the history
…ns that it doesn't force Action Controller / Active Record to load, but it doesn't fail if they have already loaded. Thanks @josevalim for the hint.
  • Loading branch information
jonleighton committed Aug 16, 2011
1 parent d0d25a9 commit 8e23615
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
2 changes: 0 additions & 2 deletions actionpack/lib/action_controller/metal/params_wrapper.rb
Expand Up @@ -121,8 +121,6 @@ def wrap_parameters(name_or_model_or_options, options = {})
_set_wrapper_defaults(_wrapper_options.slice(:format).merge(options), model) _set_wrapper_defaults(_wrapper_options.slice(:format).merge(options), model)
end end


alias :wrap_parameters= :wrap_parameters

# Sets the default wrapper key or model which will be used to determine # Sets the default wrapper key or model which will be used to determine
# wrapper key and attribute names. Will be called automatically when the # wrapper key and attribute names. Will be called automatically when the
# module is inherited. # module is inherited.
Expand Down
7 changes: 0 additions & 7 deletions actionpack/test/controller/params_wrapper_test.rb
Expand Up @@ -180,13 +180,6 @@ def test_not_wrapping_abstract_model
assert_parameters({ 'username' => 'sikachu', 'title' => 'Developer', 'user' => { 'username' => 'sikachu', 'title' => 'Developer' }}) assert_parameters({ 'username' => 'sikachu', 'title' => 'Developer', 'user' => { 'username' => 'sikachu', 'title' => 'Developer' }})
end end
end end

def test_assignment_alias
with_default_wrapper_options do
UsersController.wrap_parameters = { :format => [:foo] }
assert_equal({ :format => [:foo], :name => "user" }, UsersController._wrapper_options)
end
end
end end


class NamespacedParamsWrapperTest < ActionController::TestCase class NamespacedParamsWrapperTest < ActionController::TestCase
Expand Down
Expand Up @@ -3,12 +3,14 @@
# This file contains settings for ActionController::ParamsWrapper which # This file contains settings for ActionController::ParamsWrapper which
# is enabled by default. # is enabled by default.


<%= app_const %>.configure do # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do
config.action_controller.wrap_parameters = { <%= key_value :format, "[:json]" %> } wrap_parameters <%= key_value :format, "[:json]" %>
end


<%- unless options.skip_active_record? -%> <%- unless options.skip_active_record? -%>
# Disable root element in JSON by default. # Disable root element in JSON by default.
config.active_record.include_root_in_json = false ActiveSupport.on_load(:active_record) do
<%- end -%> self.include_root_in_json = false
end end
<%- end -%>

0 comments on commit 8e23615

Please sign in to comment.