views:

24

answers:

1
  • How will i add predefined values to a collection_select? Like...
    US
    UK
    AUS
    PAK
+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
what are these :id and :name for? it gives me the error... undefined method `name' for ["US", 1]:Array
Jamal Abdul Nasir
I've edited my answer to give you the correct information.
John Topley