I have created the following select box which works fine except for the fact if you edit the item it defaults back to N/A instead of selecting the correct location. select_tag("item[location_id]", ''<option value="">N/A</option>'' + options_for_select(@locations.collect{|location| [location.name, location.id]})) Ideally, I want to do something like this (which selects the correct value on edit): f.collection_select(:locations, @locations, :id, :name) %> but how can I add an extra blank option at the top like I did with select_tag? thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 2 Jan 2009, at 08:04, Scott Kulik wrote:> > I have created the following select box which works fine except for > the > fact if you edit the item it defaults back to N/A instead of selecting > the correct location. > > select_tag("item[location_id]", ''<option value="">N/A</option>'' + > options_for_select(@locations.collect{|location| [location.name, > location.id]})) >The (optional) last argument to options_for_select is the value to be preselected (ie something like item.location_id) Fred> Ideally, I want to do something like this (which selects the correct > value on edit): > > f.collection_select(:locations, @locations, :id, :name) %> > > but how can I add an extra blank option at the top like I did with > select_tag? > > thanks! > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
>> I have created the following select box which works fine except for >> the >> fact if you edit the item it defaults back to N/A instead of selecting >> the correct location. >> >> select_tag("item[location_id]", ''<option value="">N/A</option>'' + >> options_for_select(@locations.collect{|location| [location.name, >> location.id]})) >> > The (optional) last argument to options_for_select is the value to be > preselected (ie something like item.location_id) > > Fredah didn''t see that that. Thanks! i got it working. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---