I need to add a blank or dashed field to the options_from_collection_for_select helper but can''t seem to get it to work. Tried this, but with no effect: <%= options_from_collection_for_select @airlines, ''id'', ''name''], {:include_blank=>true} %> Anyone know how to do this? Thanks, -S -- 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 -~----------~----~----~----~------~----~------~--~---
Shandy Nantz wrote:> I need to add a blank or dashed field to the > options_from_collection_for_select helper but can''t seem to get it to > work. Tried this, but with no effect: > > <%= options_from_collection_for_select @airlines, ''id'', ''name''], > {:include_blank=>true} %>Try... options_from_collection_for_select([ nil, nil ] + @airlines, ''id'', ''name'') -- 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 -~----------~----~----~----~------~----~------~--~---
If you can use collection_select instead of options_from_collection_for_select then this code works well for me <% collection_select(:air, :id, @airlines, :id, :airline_name, {:include_blank => true, :selected => nil}) %> On Nov 8, 11:52 pm, Daniel Waite <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Shandy Nantz wrote: > > I need to add a blank or dashed field to the > > options_from_collection_for_select helper but can''t seem to get it to > > work. Tried this, but with no effect: > > > <%= options_from_collection_for_select @airlines, ''id'', ''name''], > > {:include_blank=>true} %> > > Try... > > options_from_collection_for_select([ nil, nil ] + @airlines, ''id'', > ''name'') > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Daniel Waite wrote:> options_from_collection_for_select([ nil, nil ] + @airlines, ''id'', > ''name'')This won''t work. I don''t always want to use collection_select since I don''t always need the object/model bindings (i.e. in a search form). So this worked for me: <%= select_tag "some_select", "<option></option>" + options_from_collection_for_select(@foo, "id", "item") %> This works because options_from... returns a string of <option> tags. Just add a blank option tag on to the front of the string. Cheers, David -- 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 -~----------~----~----~----~------~----~------~--~---