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)

From → Uncategorized

Leave a Comment

Leave a comment