Skip to content

Instantly share code, notes, and snippets.

@Austio
Created June 4, 2013 18:52
Show Gist options
  • Save Austio/5708452 to your computer and use it in GitHub Desktop.
Save Austio/5708452 to your computer and use it in GitHub Desktop.
f.collection_select explained
f.collection_select :x, query, :y, :z
:x = the value of the select id and name
query = the query sent to the database to return values
:y = the values in the options
:z = what you want displayed in the drop down menu
So if you have a Model that has an alias and an ID you would render it like this
:x = alias
query = Model.group(:itemtogroupby)
:y = id
:z = displayed_attribute
f.collection_select :alias, Location.group(:itemtogroupby), :value_id, :displayed_attribute
And it will render out a list that is grouped by your itemtogroupby like this
<select id="model_alias" name="model[alias]">
<option value="value_id">diplayed_attribute</option>
</select>
The value_id and displayed_attribute will be evaluated for the value of that attribute of your query.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment