All the examples of strong parameters in Rails 4 docs use
params.require(:person).permit(:name, :age)
Could someone please deconstruct and
To be more precise, when you create for eg. doing .new(...)
, there must be :person
hash indicated by require and the person hash will only accept :name
and :age
indicated by permit.
Example:
.new(person: { name: "Bhojendra", age: 32 }) // okay
.new(person: { name: "Rauniyar" }) // okay
.new(person: { name: "Bhojendra", other: 'asdf' }) // not okay, other not permitted
.new(person: { full_name: "Bhojendra Rauniyar" }) // not okay, full_name not permitted
.new(detail: { name: "Bhojendra", age: 32 }) // not okay, must be person