Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #7847 from bloudermilk/recursive_permit

ActionController::Parameters#permit! is recursive
  • Loading branch information...
commit afc81bc1bd4a668a86c303c24849bf5a74044f3b 2 parents a086e32 + 1aa522d
@dhh dhh authored
View
3  actionpack/CHANGELOG.md
@@ -1,5 +1,8 @@
## Rails 4.0.0 (unreleased) ##
+* `ActionController::Parameters#permit!` is now recursive. *Brendan
+ Loudermilk*
+
* `ActionController::Base.page_cache_extension` option is deprecated
in favour of `ActionController::Base.default_static_extension`.
View
5 actionpack/lib/action_controller/metal/strong_parameters.rb
@@ -112,6 +112,11 @@ def permitted?
# params.permitted? # => true
# Person.new(params) # => #<Person id: nil, name: "Francesco">
def permit!
+ each_pair do |key, value|
+ convert_hashes_to_parameters(key, value)
+ self[key].permit! if self[key].respond_to? :permit!
+ end
+
@permitted = true
self
end
View
7 actionpack/test/controller/parameters/parameters_permit_test.rb
@@ -57,6 +57,13 @@ class ParametersPermitTest < ActiveSupport::TestCase
assert_equal @params.permitted?, @params.dup.permitted?
end
+ test "permit is recursive" do
+ @params.permit!
+ assert @params.permitted?
+ assert @params[:person].permitted?
+ assert @params[:person][:name].permitted?
+ end
+
test "permitted takes a default value when Parameters.permit_all_parameters is set" do
begin
ActionController::Parameters.permit_all_parameters = true
Please sign in to comment.
Something went wrong with that request. Please try again.