DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Creating A Select Box On A Table's Contents

04.02.2005
| 51637 views |
  • submit to reddit
        
<%= select('user', 'sites', Site.find_all.collect  {|site| site.name}) %>
    

Comments

Snippets Manager replied on Thu, 2011/07/14 - 8:32am

Thanks, Nilesh! Technomixx.com

Snippets Manager replied on Thu, 2011/07/14 - 8:32am

Even cleaner in Rails: <%= select 'user', 'sites', Site::find_all.collect( &:name ) %> http://technomixx.com

Rick Ross replied on Sat, 2008/05/17 - 9:33am

Thanks, Nilesh!

Snippets Manager replied on Wed, 2006/11/29 - 7:40am

Another variation: <%= collection_select :user, :sites, Site.find(:all), :id, :name %> This will generate a key-value pair of site.name and site.id in the select tag.

Snippets Manager replied on Wed, 2006/11/29 - 7:40am

Another variation: <%= collection_select :user, :sites, Site.find(:all), :id, :name %> This will generate a key-value pair of site.name and site.id in the select tag.

Antonio Salazar replied on Sun, 2007/03/25 - 1:04pm

Even cleaner in Rails: <%= select 'user', 'sites', Site::find_all.collect( &:name ) %> (The important part being the &:name, the others are just oddities of my style.)