Permalink
Browse files

Allow Strings as well as Symbols as #permit parameters. Useful

when persisting multi-purpose String arrays to the #permit
call.
  • Loading branch information...
1 parent 1e238a2 commit 664d646c10943c91f5ac265535ef57e8d840f461 @bjhess bjhess committed Apr 17, 2012
Showing with 16 additions and 1 deletion.
  1. +1 −1 lib/action_controller/parameters.rb
  2. +15 −0 test/nested_parameters_test.rb
View
2 lib/action_controller/parameters.rb
@@ -37,7 +37,7 @@ def permit(*filters)
filters.each do |filter|
case filter
- when Symbol then
+ when Symbol, String then
params[filter] = self[filter] if has_key?(filter)
when Hash then
self.slice(*filter.keys).each do |key, value|
View
15 test/nested_parameters_test.rb
@@ -43,6 +43,21 @@ class NestedParametersTest < ActiveSupport::TestCase
assert_equal ["Tragedy"], permitted[:book][:genres]
end
+ test "permit may specify symbols or strings" do
+ params = ActionController::Parameters.new({
+ book: {
+ title: "Romeo and Juliet",
+ author: "William Shakespeare"
+ },
+ magazine: "Shakespeare Today"
+ })
+
+ permitted = params.permit({book: ["title", :author]}, "magazine")
+ assert_equal "Romeo and Juliet", permitted[:book][:title]
+ assert_equal "William Shakespeare", permitted[:book][:author]
+ assert_equal "Shakespeare Today", permitted[:magazine]
+ end
+
test "nested array with strings that should be hashes" do
params = ActionController::Parameters.new({
book: {

0 comments on commit 664d646

Please sign in to comment.