Many posts I found about this, and many possible solutions, but i just can''t get this simple thing to work: i tried every single solution i found: <%=select_tag "location",options_from_collection_for_select(Location.find(:all), :id, :name, "2")%> <%=select_tag "location",options_from_collection_for_select(Location.find(:all), :id, :name, 2)%> <%=select_tag "location",options_from_collection_for_select(Location.find(:all), :id, :name, {:selected=>"2"})%> <%=select_tag "location",options_from_collection_for_select(Location.find(:all), :id, :name, {:selected=>2})%> <%=select_tag "location",options_from_collection_for_select(Location.find(:all), :id, :name, {:selected_value=>"2"})%> is there anybody out there who knows how to do this? -- 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 -~----------~----~----~----~------~----~------~--~---
Hi Remco Is that a typo and there is a spcae between <%= and select_tag in your code? Remco Hh wrote:> Many posts I found about this, and many possible solutions, but i just > can''t get this simple thing to work: i tried every single solution i > found: > > <%=select_tag > "location",options_from_collection_for_select(Location.find(:all), :id, > :name, "2")%> > > <%=select_tag > "location",options_from_collection_for_select(Location.find(:all), :id, > :name, 2)%> > > <%=select_tag > "location",options_from_collection_for_select(Location.find(:all), :id, > :name, {:selected=>"2"})%> > > > <%=select_tag > "location",options_from_collection_for_select(Location.find(:all), :id, > :name, {:selected=>2})%> > > > <%=select_tag > "location",options_from_collection_for_select(Location.find(:all), :id, > :name, {:selected_value=>"2"})%> > > is there anybody out there who knows how to do this? > -- > 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 add an additional advice. Remco you should remember that RoR is designed with MVC. I disagree if you put Location.find(:all) in your view. Put it in your controller as instance variable, then put your instance variable into your view. Controller: @locations = Location.find(:all) View : <%= select_tag "location",options_from_collection_for_select(@locations, :id, :name, "2") %> Feel the taste of ROR by Optimizing MVC. Good luck. Reinhart http://teapoci.blogspot.com "Misguided in programming and paradigm?" "Ruby and Rails is your appropriate map" -- 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 am aware of that, but i am afraid that doesn''t solve my problem. Visit Indonesia 2008 wrote:> I add an additional advice. Remco you should remember that RoR is > designed with MVC. I disagree if you put Location.find(:all) in your > view. Put it in your controller as instance variable, then put your > instance variable into your view. > > Controller: > > @locations = Location.find(:all) > > View : > <%= select_tag > "location",options_from_collection_for_select(@locations, :id, > :name, "2") %> > > Feel the taste of ROR by Optimizing MVC. Good luck. > > > Reinhart > http://teapoci.blogspot.com > > "Misguided in programming and paradigm?" > "Ruby and Rails is your appropriate map"-- 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 -~----------~----~----~----~------~----~------~--~---
Controller: @locations = Location.find(:all) @selected = Location.find(2) View : <%= select_tag "location","<option value=\"@selected.id\"> @selected.name</option>"+ options_from_collection_for_select(@locations--cQVSJgZ/xLWPKud3HExfWg@public.gmane.org_a, :id, :name) %> what do you think? Reinhart http://teapoci.blogspot.com -- 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 -~----------~----~----~----~------~----~------~--~---
CORRECTION <%= select_tag "location","<option value=\"#{@selected.id}\"> #{@selected.name}</option>"+ options_from_collection_for_select(@locations--cQVSJgZ/xLWPKud3HExfWg@public.gmane.org_a, :id, :name) %>> Reinhart > http://teapoci.blogspot.com-- 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 think you will need to put the select_tag in parentheses like this. <%= select_tag( "location", options_from_collection_for_select(Location.find(:all), 2)) %> On Apr 28, 5:33 am, Remco Hh <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Many posts I found about this, and many possible solutions, but i just > can''t get this simple thing to work: i tried every single solution i > found: > > <%=select_tag > "location",options_from_collection_for_select(Location.find(:all), :id, > :name, "2")%> > > <%=select_tag > "location",options_from_collection_for_select(Location.find(:all), :id, > :name, 2)%> > > <%=select_tag > "location",options_from_collection_for_select(Location.find(:all), :id, > :name, {:selected=>"2"})%> > > <%=select_tag > "location",options_from_collection_for_select(Location.find(:all), :id, > :name, {:selected=>2})%> > > <%=select_tag > "location",options_from_collection_for_select(Location.find(:all), :id, > :name, {:selected_value=>"2"})%> > > is there anybody out there who knows how to do this? > -- > 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 -~----------~----~----~----~------~----~------~--~---
Chris Barnes:> <%= select_tag( "location", > options_from_collection_for_select(Location.find(:all), 2)) %>have you tried to run it? you will get error :) Reinhart http://teapoci.blogspot.com -- 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 -~----------~----~----~----~------~----~------~--~---
Sorry no I didn''t run it but the source of the error is easily fixed. Lookup options_from_collection_for_select in the docs. <%select_tag( "location",options_from_collection_for_select(Location.find(:all), "id", "name", 3)) %> On Apr 28, 9:34 am, Visit Indonesia 2008 <rails-mailing-l...@andreas- s.net> wrote:> Chris Barnes: > > > <%= select_tag( "location", > > options_from_collection_for_select(Location.find(:all), 2)) %> > > have you tried to run it? you will get error :) > > Reinharthttp://teapoci.blogspot.com > -- > 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 -~----------~----~----~----~------~----~------~--~---