Method: ActionView::Helpers::FormHelper#radio_button
- Defined in:
- actionview/lib/action_view/helpers/form_helper.rb
#radio_button(object_name, method, tag_value, options = {}) ⇒ Object
Returns a radio button tag for accessing a specified attribute (identified by method) on an object assigned to the template (identified by object). If the current value of method is tag_value the radio button will be checked.
To force the radio button to be checked pass checked: true in the options hash. You may pass HTML options there as well.
# Let's say that @article.category returns "rails":
("article", "category", "rails")
("article", "category", "java")
# => <input type="radio" id="article_category_rails" name="article[category]" value="rails" checked="checked" />
# <input type="radio" id="article_category_java" name="article[category]" value="java" />
# Let's say that @user.receive_newsletter returns "no":
("user", "receive_newsletter", "yes")
("user", "receive_newsletter", "no")
# => <input type="radio" id="user_receive_newsletter_yes" name="user[receive_newsletter]" value="yes" />
# <input type="radio" id="user_receive_newsletter_no" name="user[receive_newsletter]" value="no" checked="checked" />
1367 1368 1369 |
# File 'actionview/lib/action_view/helpers/form_helper.rb', line 1367 def (object_name, method, tag_value, = {}) Tags::RadioButton.new(object_name, method, self, tag_value, ).render end |