sorry again, i''m building a registration form, getting stumped on the country listbox. any ideas how i could build a listbox for countries, taking it''s content from a data table? i''d imagine i''d have to generate a data model for country, fill it in with all the current ISO spec countries; that i can do. then tie that data model to the account controller. can i use two model''s inside one controller/view? -- 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 -~----------~----~----~----~------~----~------~--~---
Certaintly, I did something similiar only with Hotels that where being read from a database: <%= select( "hotelmembership", "membership", Hotel.find_by_sql("SELECT name, id FROM hotels ORDER BY name ASC").collect {|h| [h.name, h.id]}, { :include_blank => FALSE }) %> hotelmembership is the name of the table and membership is the name of the column for the Hotel in that table. -- 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 Jul 31, 2007, at 12:35 , Shandy Nantz wrote:> <%= select( "hotelmembership", "membership", Hotel.find_by_sql("SELECT > name, id FROM hotels ORDER BY name ASC").collect {|h| [h.name, > h.id]}, { > :include_blank => FALSE }) %>It''s bad style to include database lookups in your view code. Pass the collection as an instance variable set in your controller, e.g., # in controller def new @hotels = Hotel.find(:all, :order => :name).collect { |h| [h.name, h.id] } end # in view <%= select("hotelmembership", "membership", @hotels, { :include_blank => FALSE }) %> I think you should be able to use collection_select instead # in controller def new @hotels = Hotel.find(:all, :order => :name) end # in view <%= collection_select("hotelmembership", "membership", @hotels, :id, :name, { :include_blank => FALSE }) %> Michael Glaesemann grzm seespotcode net --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
gene.tani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jul-31 21:03 UTC
Re: country listbox from table
On Jul 31, 9:45 am, John Griffiths <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> sorry again, > > i''m building a registration form, getting stumped on the country > listbox. > > any ideas how i could build a listbox for countries, taking it''s content > from a data table? > > i''d imagine i''d have to generate a data model for country, fill it in > with all the current ISO spec countries; that i can do. > > then tie that data model to the account controller. > > can i use two model''s inside one controller/view? > -- > Posted viahttp://www.ruby-forum.com/.googling around cause i figured this must be already be a plugin or something: http://rails.techno-weenie.net/forums/1/topics/536?page=1 http://blog.codahale.com/2006/04/09/usps-countries-list-for-rails/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---