Problems with select helper

Sam Newman
2005-05-01T09:08:01Z

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:

P1
P2
P3
P4

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]">

P1
P2
P3
P4


Any pointers?

--
sam