Dear all I have the following select_tag in view <%= select_tag(:event_status, options_for_select([""]) + options_from_collection_for_select(@event_status_list, :value, :detail)) %> which give the following drop down item "" Ignore Problem Normal Handling I want to set the default value to "Problem". I have used google but cannot find my desired output. I try the following, but failed... <%= select_tag(:event_status, options_for_select([""]) + options_from_collection_for_select(@event_status_list||"Problem", :value, :detail)) %> Can anyone give me some hints. Thank you. Valentino -- 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 -~----------~----~----~----~------~----~------~--~---
Valentino Lun wrote:> <%= select_tag(:event_status, options_for_select([""]) + > options_from_collection_for_select(@event_status_list, :value, :detail)) > %>The trick is recognizing options_from_collection_for_select(), not select_tag(), creates the <options>, and only they can use the selected=''selected'' attribute. Google for options_from_collection_for_select() and "default value"... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
<%= select_tag(:event_status, options_for_select([""]) + options_from_collection_for_select (@event_status_list||"Problem", :value, :detail, @selected_status)) %> See http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M001596 On Apr 9, 12:34 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Valentino Lun wrote: > > <%= select_tag(:event_status, options_for_select([""]) + > > options_from_collection_for_select(@event_status_list, :value, :detail)) > > %> > > The trick is recognizing options_from_collection_for_select(), not select_tag(), > creates the <options>, and only they can use the selected=''selected'' attribute. > > Google for options_from_collection_for_select() and "default value"...--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hadn''t realized that you were trying to specify "Problem" as the default. Note that if your :value method gives another result for "Problem", like for example, 1, then you have to change the selected field accordingly. <%= select_tag(:event_status, options_for_select([""]) + options_from_collection_for_select (@event_status_list, :value, :detail, "Problem")) %> On Apr 9, 2:53 pm, Jaryl Sim <quantum.crus...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> <%= select_tag(:event_status, options_for_select([""]) + > options_from_collection_for_select > (@event_status_list||"Problem", :value, :detail, @selected_status)) > %> > > Seehttp://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelp... > > On Apr 9, 12:34 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Valentino Lun wrote: > > > <%= select_tag(:event_status, options_for_select([""]) + > > > options_from_collection_for_select(@event_status_list, :value, :detail)) > > > %> > > > The trick is recognizing options_from_collection_for_select(), not select_tag(), > > creates the <options>, and only they can use the selected=''selected'' attribute. > > > Google for options_from_collection_for_select() and "default value"...--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---