Skip to content
This repository has been archived by the owner on Aug 17, 2017. It is now read-only.

Commit

Permalink
Allow Strings as well as Symbols as #permit parameters. Useful
Browse files Browse the repository at this point in the history
when persisting multi-purpose String arrays to the #permit
call.
  • Loading branch information
bjhess committed Apr 17, 2012
1 parent 1e238a2 commit 664d646
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/action_controller/parameters.rb
Expand Up @@ -37,7 +37,7 @@ def permit(*filters)


filters.each do |filter| filters.each do |filter|
case filter case filter
when Symbol then when Symbol, String then
params[filter] = self[filter] if has_key?(filter) params[filter] = self[filter] if has_key?(filter)
when Hash then when Hash then
self.slice(*filter.keys).each do |key, value| self.slice(*filter.keys).each do |key, value|
Expand Down
15 changes: 15 additions & 0 deletions test/nested_parameters_test.rb
Expand Up @@ -43,6 +43,21 @@ class NestedParametersTest < ActiveSupport::TestCase
assert_equal ["Tragedy"], permitted[:book][:genres] assert_equal ["Tragedy"], permitted[:book][:genres]
end 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 test "nested array with strings that should be hashes" do
params = ActionController::Parameters.new({ params = ActionController::Parameters.new({
book: { book: {
Expand Down

0 comments on commit 664d646

Please sign in to comment.