- How will i add predefined values to a collection_select? Like...
US
UK
AUS
PAK
views:
24answers:
1
+3
A:
The collection_select
helper is used for when you want the options within the select element to come from a collection of ActiveRecord models. For your requirements you should use the select
helper in combination with options_for_select
:
<%= select(:country, :country_id,
options_for_select([['US', 1], ['UK', 2], ['AUS', 3], ['PAK', 4]])) %>
John Topley
2010-06-16 13:43:48
what are these :id and :name for? it gives me the error... undefined method `name' for ["US", 1]:Array
Jamal Abdul Nasir
2010-06-16 13:49:54
I've edited my answer to give you the correct information.
John Topley
2010-06-16 14:07:39