Skip to content

Commit

Permalink
Merge pull request #7915 from frodsan/docs_permit
Browse files Browse the repository at this point in the history
update AC::Parameters#permit documentation [ci skip]
  • Loading branch information
rafaelfranca committed Oct 12, 2012
2 parents bdd105d + 299fee5 commit fc5a3e9
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions actionpack/lib/action_controller/metal/strong_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit fc5a3e9

Please sign in to comment.