# Select selected not working

**URL:** <https://www.ruby-forum.com/t/select-selected-not-working/74333>\
**Category:** Rails\
**Created:** [November 4, 2006, 7:10pm UTC](https://www.ruby-forum.com/t/select-selected-not-working/74333 "2006-11-04T19:10:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andreas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ee7513/32.png) [@andreas](https://www.ruby-forum.com/u/andreas)\
**Post date:** [November 4, 2006, 7:10pm UTC](https://www.ruby-forum.com/t/select-selected-not-working/74333/1 "2006-11-04T19:10:39Z")

</div>

Hi all,

I have this very simple code:

\<% for country in @countries -%\>  
\<% if country.id == @user.country %\>

\<%= country.name %\> \<% else %\> \<%= country.name %\> \<% end %\> \<% end -%\>

this produces a list of countrynames and when the user country is the  
same it should select it. It does select it - but the select drop down  
is showing the first entry instead of the selected one???

any ideas?  
I dont know whats up with that

thanks for any tip  
andreas

---

<div class="post-metadata">

**Author:** ![andreas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ee7513/32.png) [@andreas](https://www.ruby-forum.com/u/andreas)\
**Post date:** [November 4, 2006, 7:17pm UTC](https://www.ruby-forum.com/t/select-selected-not-working/74333/2 "2006-11-04T19:17:00Z")

</div>

ehhhh…  
this is not true or?  
in rails is a complete country list???

I found this here:  
country\_select(object, method, priority\_countries = nil, options = {},  
html\_options = {})

I build my own database with countries today:(  
it seams there is a command for anything in rails  
aaaahhhh… my whole day of work to build the country database is not  
needed

andreas

---

<div class="post-metadata">

**Author:** ![andreas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ee7513/32.png) [@andreas](https://www.ruby-forum.com/u/andreas)\
**Post date:** [November 4, 2006, 7:26pm UTC](https://www.ruby-forum.com/t/select-selected-not-working/74333/3 "2006-11-04T19:26:20Z")

</div>

ok, found the problem

it was a chaching problem of firefox 😕  
and I replaced my ugly styled country selector with the fresh and easy  
to use rails verson

\<%=select(“user”, “country”, Country.find\_all.collect {|p| [ p.name,  
p.id ] }, { :include\_blank =\> true }, :class =\> ‘input’, :style =\>  
‘width:255px’) %\>

live can be so easy

andreas
