Web Development

This is note to myself when working with Rails helpers.

The select helper is useful for creating a select tag. Creating options for the select helper is quite easy:

If you have static content:

f.select :country, [['Philippines', 1], ['Hong Kong', 2], ['Indonesia', 3]]

If you have Model access:

f.select :country Country.all.collect{|u| [u.name, u.id]

While you can do the thing above If you have access to the Model, a nice way to do it is using the collection_select helper instead which is built on top of the select helper:

f.collection_select :country_id, Country.all, :id, :name