- Form
FormTagHelper Version:
<% form_tag 'show' do %>
... Controls go here.
<% end %>
FormHelper Version:
<% form_for @item, url: convert_show_path do |f| %>
... Controls go here.
<% end %>
- Textfield
FormTagHelper Version:
<%= text_field_tag :celsius, '20', class: 'tf' %>
:celsius is the name; '20' is the initial value.
FormHelper Version:
<%= f.text_field :celsius, class: 'tf' %>
:celsius is the field of the database object f.
- Dropdown Menu
FormTagHelper Version 1:
<%= select_tag :source_rate,
options_for_select(
[['Dollars', 1.00000],
['Euro', 1.36749],
['Pesos', 12.6149],
['Pounds', 1.58228]]),
class: 'ddm' %>
:source_rate is the name;
the first column of the array are the values displayed in the
dropdown menu; the second column are the values returned to the
controller to be read by a params statement.
The option tags are the HTML option tags.
FormTagHelper Version 2:
<%= select_tag :source_rate,
options_from_collection_for_select(
@exchange_rates, :curr_name, :rate),
class: 'ddm' %>
:source_rate is the name;
the options_from_collection_for_select method takes three arguments:
(1) @exchange_rates: the collection containing the information for the dropdown menu,
(2) :curr_rate: the field value to send to the server to
be read in the params array,
(3)
:curr_name: the field to display in the dropdown menu.
FormHelper Version:
<%= f.select :source_rate,
[['Dollars', 1.00000],
['Euro', 1.36749],
['Pesos', 12.6149],
['Pounds', 1.58228]],
class: 'ddm' %>
:source_rate is the field of the database object
f; the values of the dropdown menu are specified in the
array as they were in the FormTagHelper version. Note that for the FormHelper version,
no options_for_select method is needed.
- Radio Button
FormTagHelper Version:
<%= radio_button_tag :group, value, true %>
:group sets the button group (in a group of radio buttons, only can be
checked at a time)
:value is the value returned to the controller
to be read by a params statement
true means that the radio button should be
initially checked.
FormHelper Version:
<%= f.radio_button :group, value, checked: true %>
:group sets the button group (in a group of radio buttons, only can be
checked at a time)
value is the value returned to the controller
to be read by a params statement
checked: true means that the radio button should be
initially checked.
- CheckBox
FormTagHelper Version:
<%= check_box_tag :sugar, 1, true, class: 'cb' %>
:sugar is the name of the checkbox
1 is the value returned to the controller in a params statement
false means that the checkbox is initially checked.
FormHelper Version:
<%= f.check_box :sugar, 1, checked: true, class: 'cb' %>
:sugar is the name of the checkbox
1 is the value returned to the controller in a params statement,
0 is returned if the box is not checked.
checked: true means that the checkbox is initially checked.