Skip to content
Tags

,

.select vs .collection_select

April 5, 2011

I think this is the difference between them.
.select expects an array given to it. It requires the array to be well formatted to its needs. But too often the data is available in something like a model but the model does not have a method (which is should not) that will return the array well formatted to its needs.
This is where .collection select helps.
The following two are equivalent:

authorship.select(:author_id, Author.all.map{|a| [a.name, a.id]} , :include_blank => true)
authorship.collection_select(:author_id, Author.all, :id, :name, :include_blank => true)
Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: