Generating Model Objects from Raw Form Data - Need a one-to-one field match?
If I say this in my controller:
@order = Order.new(params[:order])
What is required for this?
Should there be a one-to-one match between all fields in params[:order]
and the order model?
Or maybe there are more or fewer fields in the params[:order]
order than are required to create an instance of the order?
a source to share
params [: order] should itself be a hash, where each key is the name of a field in the model. To see how Rails translates form field names to params hashes, write a view template using the form_for helper and a view source.
There may be more or less fields, yes. Additional fields will be ignored. Smaller fields will simply not be copied to the instance object. You don't need to instantiate an ActiveRecord object at all. (Object validation and persistence is a different story - they invoke checks and the ActiveRecord callback mechanism.)
a source to share