Method: SimpleForm::ActionViewExtensions::Builder#collection_radio
- Defined in:
- lib/simple_form/action_view_extensions/builder.rb
#collection_radio(attribute, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
Create a collection of radio inputs for the attribute. Basically this helper will create a radio input associated with a label for each text/value option in the collection, using value_method and text_method to convert these text/value. You can give a symbol or a proc to both value_method and text_method, that will be evaluated for each item in the collection.
Examples
form_for @user do |f|
f.collection_radio :options, [[true, 'Yes'] ,[false, 'No']], :first, :last
end
<input id="user_options_true" name="user[options]" type="radio" value="true" />
<label class="collection_radio" for="user_options_true">Yes</label>
<input id="user_options_false" name="user[options]" type="radio" value="false" />
<label class="collection_radio" for="user_options_false">No</label>
Options
Collection radio accepts some extra options:
* checked => the value that should be checked initially.
* disabled => the value or values that should be disabled. Accepts a single
item or an array of items.
* collection_wrapper_tag => the tag to wrap the entire collection.
* item_wrapper_tag => the tag to wrap each item in the collection.
38 39 40 41 42 43 44 45 |
# File 'lib/simple_form/action_view_extensions/builder.rb', line 38 def collection_radio(attribute, collection, value_method, text_method, ={}, ={}) render_collection( attribute, collection, value_method, text_method, , ) do |value, text, | radio = (attribute, value, ) collection_label(attribute, value, radio, text, :class => "collection_radio") end end |