I''ve searched the wiki & docs, but the select helper still has me
stumped. I have a Thing object which has a Priority - I want to
display a combo box for the Priority when editing Thing. The following
code displays the select, but without correctly marking the current
priority:
select("thing", "priority_id", priorities.collect {|p|
[p.name, p.id])
Looking at the docs, the choices parameter (3rd one) takes the same
form as options_for_select. I tried using options_for_select directly,
and it displays the options, including the selected item:
options_for_select(priorities.collect {|p| [p.name, p.id]} ,
selected_priority_id)
giving:
<option value="1" selected>P1</option>
<option value="2">P2</option>
<option value="3">P3</option>
<option value="4">P4</option>
I try passing arguments in the same form for select, but think I''m
triping over some syntax problems (too many types of brakets!) as the
selected parameter from options_for_select seems to get picked up by
select as a request for a blank option:
select("thing", "priority_id", priorities.collect {|p|
[p.name, p.id])
gives:
<select id="thing_priority_id"
name="thing[priority_id]">
<option value=""></option>
<option value="1">P1</option>
<option value="2">P2</option>
<option value="3">P3</option>
<option value="4">P4</option>
</select>
Any pointers?
--
sam
http://www.magpiebrain.com/