- 1.0.0 (0)
- 1.1.6 (0)
- 1.2.6 (0)
- 2.0.3 (38)
- 2.1.0 (22)
- 2.2.1 (0)
- 2.3.8 (1)
- 3.0.0 (-7)
- 3.0.9 (-6)
- 3.1.0 (-1)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (32)
- 4.1.8 (-2)
- 4.2.1 (-3)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (0)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (1)
- 7.1.3.4 (0)
- What's this?
Provides a set of methods for working with forms and especially forms related to objects assigned to the template. The following is an example of a complete form for a person object that works for both creates and updates built with all the form helpers. The @person object was assigned by an action on the controller:
<form action="save_person" method="post"> Name: <%= text_field "person", "name", "size" => 20 %> Password: <%= password_field "person", "password", "maxsize" => 20 %> Single?: <%= check_box "person", "single" %> Description: <%= text_area "person", "description", "cols" => 20 %> <input type="submit" value="Save"> </form>
…is compiled to:
<form action="save_person" method="post"> Name: <input type="text" id="person_name" name="person[name]" size="20" value="<%= @person.name %>" /> Password: <input type="password" id="person_password" name="person[password]" size="20" maxsize="20" value="<%= @person.password %>" /> Single?: <input type="checkbox" id="person_single" name="person[single]" value="1" /> Description: <textarea cols="20" rows="40" id="person_description" name="person[description]"> <%= @person.description %> </textarea> <input type="submit" value="Save"> </form>
If the object name contains square brackets the id for the object will be inserted. Example:
<%= text_field "person[]", "name" %>
…becomes:
<input type="text" id="person_<%= @person.id %>_name" name="person[<%= @person.id %>][name]" value="<%= @person.name %>" />
If the helper is being used to generate a repetitive sequence of similar form elements, for example in a partial used by render_collection_of_partials, the "index" option may come in handy. Example:
<%= text_field "person", "name", "index" => 1 %>
becomes
<input type="text" id="person_1_name" name="person[1][name]" value="<%= @person.name %>" />
There’s also methods for helping to build form tags in ActionView::Helpers::FormOptionsHelper ActionView::Helpers::DateHelper and ActionView::Helpers::ActiveRecordHelper