i am creating multiple drop down menus using <%= form.select(:choice, @list.map { | item | [ item[0], item[1] ] }) %> this works great but when the client hits submit and there are other validation errors it resets the drop down menu. how do i maintain the selected item. my search for the options of the slect method has come up empty. @list is created in the controller and used in the view. can you not test :choice to see if the user has choose an item and then display the drop down with the correct item selected. thanks. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
sorry, don''t have the time to go into details right now, but maybe that''ll help you a bit: <%= select_tag "client[branch][]", options_for_select([[''Automatisering'',''1''], [''Bouwnijverheid'', ''2''], [''Communicatie Intern'', ''3''], [''Communicatie Extern'', ''4''], [''Cultuur'', ''5''], [''Detailhandel food'', ''6''], [''Detailhandel non food'', ''7''], [''Drukkerij'', ''8''], [''Facilitaire dienst'', ''9''], [''Financiele dienstverlener'', ''10''], [''Gezondheidszorg'', ''11''], [''Handel'', ''12''], [''Industrie'', ''13''], [''IT'', ''14''], [''Mediabureau'', ''15''], [''Overheid'', ''16''], [''Onderwijs'', ''17''], [''Onderzoek'', ''18''], [''Reclamebureau'', ''19''], [''Recreatie & toerisme'', ''20''], [''Telecom'', ''21''], [''Transport sector'', ''22''], [''Uitgeverij dag-en weekbladen'', ''23''], [''Uitgeverij publieksbladen'', ''24''], [''Uitgeverij vakbladen'', ''25''], [''Uitgeverij relatiemagazines'', ''26''], [''Zakelijk adviesbureau'', ''27''], [''Overig'', ''28'']], @client.branch), :multiple => true, :size => 7, :id => "client_branch" %> in this case @client.branch holds an array of ids that are selected, but could be a single element too http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M000944 options_from_collection_for_select may be another alternative and the "choices" parameter of form.select works just the same as options_for_select -- 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 -~----------~----~----~----~------~----~------~--~---
still not close? On Apr 23, 11:30 am, Thorsten Mueller <rails-mailing-l...@andreas- s.net> wrote:> sorry, don''t have the time to go into details right now, but maybe > that''ll help you a bit: > > <%= select_tag "client[branch][]", > options_for_select([[''Automatisering'',''1''], > [''Bouwnijverheid'', ''2''], > [''Communicatie Intern'', ''3''], [''Communicatie > Extern'', ''4''], [''Cultuur'', ''5''], > [''Detailhandel food'', ''6''], [''Detailhandel non > food'', ''7''], [''Drukkerij'', ''8''], > [''Facilitaire dienst'', ''9''], [''Financiele > dienstverlener'', ''10''], > [''Gezondheidszorg'', ''11''], > [''Handel'', ''12''], > [''Industrie'', ''13''], [''IT'', ''14''], > [''Mediabureau'', ''15''], > [''Overheid'', ''16''], [''Onderwijs'', ''17''], > [''Onderzoek'', ''18''], > [''Reclamebureau'', ''19''], [''Recreatie & > toerisme'', ''20''], > [''Telecom'', ''21''], [''Transport sector'', ''22''], > [''Uitgeverij dag-en weekbladen'', ''23''], > [''Uitgeverij publieksbladen'', ''24''], [''Uitgeverij vakbladen'', ''25''], > [''Uitgeverij relatiemagazines'', ''26''], > [''Zakelijk adviesbureau'', ''27''], [''Overig'', > ''28'']], @client.branch), :multiple => true, :size => 7, :id => > "client_branch" %> > > in this case @client.branch holds an array of ids that are selected, but > could be a single element too > > http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelp... > > options_from_collection_for_select may be another alternative and the > "choices" parameter of form.select works just the same as > options_for_select > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
1 <select id="stuff_item_id" name="stuff[item_id]"> 2 <% if @stuff.item_id == 0 or @stuff.item_id == nil -%> 3 <option value="" selected="selected" >Please Selected An Item</ option> 4 <% end -%> 5 <% @items = Item.find(:all, :order => "name") 6 @items.each do |item| %> 7 <option value="<%= item.id %>" 8 <% if @stuff.item_id == item.id -%> selected="selected"<% end -%> 9 > 10 <%= item.name %> (<%= item.description %>) 11 </option> 12 <% end %> 13 </select> is this the only method to handle a drop down menu. looks like it is comparing the value selected with the item and then setting to selected. this would be a pain if you have a lot of drop down menus in an application. any suggestions to preserving the item selected by a user. the items of the drop down menu do not come from a simple search, at times they are combined from multiple searches, but basically i have an array, with display item, id# which is passed to the view. On Apr 23, 12:30 pm, rushnosh <rashan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> still not close? > > On Apr 23, 11:30 am, Thorsten Mueller <rails-mailing-l...@andreas- > > s.net> wrote: > > sorry, don''t have the time to go into details right now, but maybe > > that''ll help you a bit: > > > <%= select_tag "client[branch][]", > > options_for_select([[''Automatisering'',''1''], > > [''Bouwnijverheid'', ''2''], > > [''Communicatie Intern'', ''3''], [''Communicatie > > Extern'', ''4''], [''Cultuur'', ''5''], > > [''Detailhandel food'', ''6''], [''Detailhandel non > > food'', ''7''], [''Drukkerij'', ''8''], > > [''Facilitaire dienst'', ''9''], [''Financiele > > dienstverlener'', ''10''], > > [''Gezondheidszorg'', ''11''], > > [''Handel'', ''12''], > > [''Industrie'', ''13''], [''IT'', ''14''], > > [''Mediabureau'', ''15''], > > [''Overheid'', ''16''], [''Onderwijs'', ''17''], > > [''Onderzoek'', ''18''], > > [''Reclamebureau'', ''19''], [''Recreatie & > > toerisme'', ''20''], > > [''Telecom'', ''21''], [''Transport sector'', ''22''], > > [''Uitgeverij dag-en weekbladen'', ''23''], > > [''Uitgeverij publieksbladen'', ''24''], [''Uitgeverij vakbladen'', ''25''], > > [''Uitgeverij relatiemagazines'', ''26''], > > [''Zakelijk adviesbureau'', ''27''], [''Overig'', > > ''28'']], @client.branch), :multiple => true, :size => 7, :id => > > "client_branch" %> > > > in this case @client.branch holds an array of ids that are selected, but > > could be a single element too > > >http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelp... > > > options_from_collection_for_select may be another alternative and the > > "choices" parameter of form.select works just the same as > > options_for_select > > -- > > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---