string options_for_select(
string[]
$choices, [integer
$selected = null])
|
|
Generate HTML option tags from a list of choices
Accepts an array of possible choices and returns a string of option tags. The value of each array element becomes the visible text of an option, and the key of the element becomes the value returned to the server. For example:
options_for_select(array('foo','bar'));
will return:
<option value="0">foo</option>\n
<option value="1">bar</option>
The optional second argument specifies the array key of an option to be initially selected.
NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
Tags:
Parameters:
void options_from_collection_for_select(
mixed
$collection, mixed
$attribute_value, mixed
$attribute_text, [mixed
$selected_value = null])
|
|
Returns a string of option tags that have been compiled by
iterating over the +collection+ and assigning the result of a call to the +value_method+ as the option value and the +text_method+ as the option text. If +selected_value+ is specified, the element returning a match on +value_method+ will get the selected option tag.
Example (call, result). Imagine a loop iterating over each +person+ in <tt>@project.people</tt> to generate an input tag: options_from_collection_for_select(@project.people, "id", "name") <option value="#{person.id}">#{person.name}</option>
NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
Tags: