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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2007-Feb-20 01:34 UTC
Re: Problems with select and :prompt => "--select--"
jake wrote:> Even when my object is @product.product_type_id = 0 I don''t ever see > the --select-- unless I set :selected => nilThe :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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---