Problems with select and :prompt => "--select--"

I have a select list with three options. When I am adding a new
product I want the selected item to be “–select–” when I go to
update I want the selected item to come from the object data. My code
looks like this

<%=
select (
“product”,
:product_type_id,
ProductType.find(:all, :order => “label”).map {|type|
[type.label, type.id]},
:prompt => “-- Select --”
)
%>

Even when my object is @product.product_type_id = 0 I don’t ever see
the --select-- unless I set :selected => nil

What am I doing wrong?

jake wrote:

Even when my object is @product.product_type_id = 0 I don’t ever see
the --select-- unless I set :selected => nil

The :prompt option only adds the prompt if the selected value is either
nil or the empty string. So you’ll either have to change the DB field
to “default NULL”, or manually generate your own prompt option.


We develop, watch us RoR, in numbers too big to ignore.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs