Reputation: 13378
I currently have my index.html.erb showing the following code.
<select name="country">
<option>All</option>
<%= country_options_for_select('All') %>
</select>
But the result of the page becomes like this in the html source:
<select name="country">
<option>All</option>
<optionvalue="Afghanistan">Afghanistan</option><optionvalue="Aland
Islands">AlandIslands</option> ...
</select>
It should be instead of <option>
What did I do wrong?
Upvotes: 0
Views: 405
Reputation: 13378
In Rails 2.3.14 to Rails 3.1.0, this works:
<%= country_options_for_select.html_safe %>
Upvotes: 1
Reputation: 1211
Try using select_tag instead. It looks a bit cleaner.
<%= select_tag "name", country_options_for_select() %>
The reason the country options are showing up incorrectly is because you are passing 'All' to it. It doesn't need an argument there in your case. Only if you wanted a certain option selected by default.
For example,
<%= select_tag "name", country_options_for_select('Chile') %>
More info on it's use here: http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/country_options_for_select
Upvotes: 1