- Form
<%= form_tag 'show' do %>
... Controls go here.
<% end %>
- 'show' is the action, which is taken when the submit button is
clicked.
- do means that everything until the end statement is included in
the form.
- The equals sign is not used in the Rails delimiter for the end statement
because end is a control statement.
- Textfield
<%= text_field_tag :cel, @c, :class => 'ctrl' %>
- :cel is the name of the textfield control.
- @c is the initial value of the textfield.
- Submit
<%= submit_tag 'Convert Temperature',
:class => 'ctrl' %>
- 'Convert Temperature' is the text of the submit control.
- When the submit control is clicked, the action specified in the
form_tag control is executed.
- Dropdown Menu
<%= select_tag :source_rate,
options_for_select([["Dollars", "1.00000"],
["Euro", "1.36749"],
["Pesos", "12.6149"],
["Pounds", "1.58228"]]),
:class => 'ctrl' %>
:source_rate is the name
the option tags are the HTML option tags.
- Radio Button
<%= 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
in a params statement
true means that the radio button should be
initially checked.
- Check Box
<%= check_box_tag :sugar, 1, false %>
:sugar is the name
1 is the value returned to the controller in a params statement
false means that the checkbox is initially not checked.