Created
June 4, 2013 18:52
-
-
Save Austio/5708452 to your computer and use it in GitHub Desktop.
f.collection_select explained
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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