Skip to content
This repository
Browse code

Don't refer to ActionController::Base in the wrap_parameters initiali…

…zer - use config object instead. Cuts about 15% off the load time. (#734)
  • Loading branch information...
commit 6cf15ae56a2d5acead326469ccdae8438eefd4a5 1 parent c388a95
Jon Leighton jonleighton authored
2  actionpack/lib/action_controller/metal/params_wrapper.rb
@@ -121,6 +121,8 @@ def wrap_parameters(name_or_model_or_options, options = {})
121 121 _set_wrapper_defaults(_wrapper_options.slice(:format).merge(options), model)
122 122 end
123 123
  124 + alias :wrap_parameters= :wrap_parameters
  125 +
124 126 # Sets the default wrapper key or model which will be used to determine
125 127 # wrapper key and attribute names. Will be called automatically when the
126 128 # module is inherited.
7 actionpack/test/controller/params_wrapper_test.rb
@@ -180,6 +180,13 @@ def test_not_wrapping_abstract_model
180 180 assert_parameters({ 'username' => 'sikachu', 'title' => 'Developer', 'user' => { 'username' => 'sikachu', 'title' => 'Developer' }})
181 181 end
182 182 end
  183 +
  184 + def test_assignment_alias
  185 + with_default_wrapper_options do
  186 + UsersController.wrap_parameters = { :format => [:foo] }
  187 + assert_equal({ :format => [:foo], :name => "user" }, UsersController._wrapper_options)
  188 + end
  189 + end
183 190 end
184 191
185 192 class NamespacedParamsWrapperTest < ActionController::TestCase
2  railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt
@@ -4,7 +4,7 @@
4 4 # is enabled by default.
5 5
6 6 # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7   -ActionController::Base.wrap_parameters <%= key_value :format, "[:json]" %>
  7 +<%= app_const %>.config.wrap_parameters <%= key_value :format, "[:json]" %>
8 8
9 9 # Disable root element in JSON by default.
10 10 if defined?(ActiveRecord)

0 comments on commit 6cf15ae

Please sign in to comment.
Something went wrong with that request. Please try again.