Browse files

update AC::Parameters#permit documentation [ci skip]

bdd105d changes the behaviour of AC::Parameters#permit.
  • Loading branch information...
1 parent bdd105d commit 299fee5919ec41290421684436a50105c4ddc485 Francesco Rodriguez committed Oct 11, 2012
Showing with 22 additions and 0 deletions.
  1. +22 −0 actionpack/lib/action_controller/metal/strong_parameters.rb
View
22 actionpack/lib/action_controller/metal/strong_parameters.rb
@@ -171,6 +171,28 @@ def require(key)
# permitted[:person][:age] # => nil
# permitted[:person][:pets][0][:name] # => "Purplish"
# permitted[:person][:pets][0][:category] # => nil
+ #
+ # Note that if you use +permit+ in a key that points to a hash,
+ # it won't allow all the hash. You also need to specify which
+ # attributes inside the hash should be whitelisted.
+ #
+ # params = ActionController::Parameters.new({
+ # person: {
+ # contact: {
+ # email: 'none@test.com'
+ # phone: '555-1234'
+ # }
+ # }
+ # })
+ #
+ # params.require(:person).permit(:contact)
+ # # => {}
+ #
+ # params.require(:person).permit(contact: :phone)
+ # # => {"contact"=>{"phone"=>"555-1234"}}
+ #
+ # params.require(:person).permit(contact: [ :email, :phone ])
+ # # => {"contact"=>{"email"=>"none@test.com", "phone"=>"555-1234"}}
def permit(*filters)
params = self.class.new

0 comments on commit 299fee5

Please sign in to comment.