When the model receives form parameters with empty parameters, the fields of these fields will have the nil parameter. Therefore, if you initialize the same @foo = 'bar' and the user submission form with empty parameters [: foo], then Model.create (params [: model]) will have foo => nil.
- You can check all the parameters before the object is created.
You can set default parameters in your database structure through migrations:
create_table: comments do | t |
t.text: comment ,: default => 'bar'
end
source share