views:

13

answers:

1

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>
&lt;optionvalue=&quot;Afghanistan&quot;&gt;Afghanistan&lt;/option&gt;&lt;optionvalue=&quot;Aland
Islands&quot;&gt;AlandIslands&lt;/option&gt; ... 
</select>

It should be instead of <option>

What did I do wrong?

A: 

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

John Dyer
Hmm, doesn't work. The result is still <select id="country" name="country"><option value="Afghanistan">Afghanistan</option><option value="Aland Islands">Aland Islands</option>
Victor