Topic: Introduction to Form Helpers
Form helpers are methods to aid in the creation of HTML forms. For example, this will create a text field with the name 'foo':
<%= text_field_tag :foo %>
Whatever the user types into this text field can be accessed in the next controller action using params[:foo].
Regular vs. Model Form Helpers
There are two types of form helpers. I'm calling these "regular" and "model". You are probably mostly familiar with the model form helpers which scaffolding generates. An example of a model form helper is this:
<%= text_field :person, :name %>
This helper is used to edit the name attribute inside the @person model. The value will be accessible in the controller using params[:person][:name]. But, take a look at the first code example I gave. Notice the extra "_tag" at the end of the method name? Although it might seem like the same thing, "text_field" and "text_field_tag" are two very different methods.
The regular form helpers usually end in "_tag" and aren't related to models in any way. They can be used for anything.
The model form helpers, on the other hand, are used for editing a model's attributes. In the person code example I gave above, it will look for an instance variable called @person. If @person.name is set, it will automatically set the text field to this value. If you were using text_field_tag, you would need to specify the value manually.
When not to use model helpers
Let's say you are adding a search to your site. Don't do this:
<%= text_field :search, :query %>
Most likely there isn't a model called Search, nor does it have an attribute called "query", so you shouldn't use this type of form helper. Instead, use the normal text_field_tag helper like this:
<%= text_field_tag :query %>
Conclusion
Now you know when to use the regular form helpers vs. the model specific form helpers. In this article I only used the text_field helper as an example, but the same rule applies to the other form helpers as well (check_box, radio, select, etc.). There are only a few exceptions (such as date_select vs. select_date, that one always gets me).