Rails provides helpers for producing two kinds of forms: simple forms and model-based forms. The differences are summarized in the table below. The examples assume that the model has the name Item and that the attribute has the name color.
Scaffolded views use model-based forms.
Form Type | Simple form | Model-based form |
---|---|---|
Helper | <%= form_tag submit_path do %> | <%= form_for(@item) do |f| %> |
Text field tag | <%= text_field__tag :color %> | <%= f.text_field :color %> |
Parameter use | params[:color] | params[:item][:color] |
Comments | Each form attribute produces a separate parameter. | All model attributes are bundled in a hash table and referenced by the model name (e.g. params[:item]). Scaffolded code uses a model-based form. If the model object has attribute values, those values are displayed in the form. |