Created
March 22, 2012 18:51
-
-
Save sameera207/2161748 to your computer and use it in GitHub Desktop.
Using selected option in rails select_tag
This file contains hidden or 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
year array -> ['2012','2011','2010','2009'] | |
selected year -> 2010 | |
<%= select_tag 'year_range', options_for_select(['2012','2011','2010','2009'],'2010') %> | |
which will always selects '2010' | |
If you are selecting an object | |
if the form is -> f | |
collection is @ages | |
selected index is always 3 | |
<%= f.select :age, options_from_collection_for_select(@ages, "id", "age",'3') %> | |
resources | |
http://stackoverflow.com/questions/7347039/rails-select-tag-selected-value | |
http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/options_from_collection_for_select | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!