permit!

permit!()
Instance Public methods

Sets the permitted attribute to true. This can be used to pass mass assignment. Returns self.

1
2
3
4
5
6
7
8
9
class Person < ActiveRecord::Base
end
 
params = ActionController::Parameters.new(name: 'Francesco')
params.permitted?  # => false
Person.new(params) # => ActiveModel::ForbiddenAttributesError
params.permit!
params.permitted?  # => true
Person.new(params) # => #<Person id: nil, name: "Francesco">
doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.