Never been to DZone Snippets before?

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

creating a select box on a table's contents (See related posts)

<%= select('user', 'sites', Site.find_all.collect  {|site| site.name}) %>

Comments on this post

Shadowfiend posts on Mar 30, 2007 at 21:40
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.)
nilesh posts on May 15, 2007 at 00:37
Another variation:

&lt;%= collection_select :user, :sites, Site.find(:all), :id, :name %&gt;


This will generate a key-value pair of site.name and site.id in the select tag.
nilesh posts on May 15, 2007 at 00:37
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.

You need to create an account or log in to post comments to this site.


Click here to browse all 4863 code snippets

Related Posts