# Form.select problem

**URL:** <https://www.ruby-forum.com/t/form-select-problem/116903>\
**Category:** Rails\
**Created:** [October 11, 2007, 12:05am UTC](https://www.ruby-forum.com/t/form-select-problem/116903 "2007-10-11T00:05:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f9ae1b/32.png) [@nick](https://www.ruby-forum.com/u/nick)\
**Post date:** [October 11, 2007, 12:05am UTC](https://www.ruby-forum.com/t/form-select-problem/116903/1 "2007-10-11T00:05:20Z")

</div>

Dear all,

I tried to implement the code for 2 select boxes that are dependent on  
each other. One has a list of countries, and one a list of states.  
Now, this code works:

 \<%= select :state, :id, Country.find(@country.id).states.map {|x| [x.name, x.id]} %\>
\<%= select :country, :id, Country.find(:all, :order =\> 'name ASC').map {|x| [x.name, x.id]} %\>

However, I want to place this inside my form\_for. This code does not  
work:

\<% form\_for (:trail, :url =\> { :action =\> “update”, :id =\>  
@trail }, :html =\> { :multipart =\> true }) do |form| %\>

 \<%= select :state, :id, Country.find(@country.id).states.map {|x| [x.name, x.id]} %\> 
 \<%= select :country, :id, Country.find(:all, :order =\> 'name ASC').map {|x| [x.name, x.id]} %\> \<%= submit\_tag "Save" %\> \<% end %\>

The view crashes with this error message:

ActionView::TemplateError (undefined method `merge’ for #\<Array:  
0x33d1b68\>) on line #110 of app/views/trail\_editor/edit.rhtml:  
107:   
108:

  
109: Country:  
110: \<%= form.select :country, :id, Country.find(:all,  
:order  
=\> ‘name ASC’).map {|x| [x.name, x.id]} %\>  
111:   
112:   
113: Directions  
to Trailhead:

Any help would be greatly appreciated.

Thank you,

---

<div class="post-metadata">

**Author:** ![nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f9ae1b/32.png) [@nick](https://www.ruby-forum.com/u/nick)\
**Post date:** [October 11, 2007, 5:29am UTC](https://www.ruby-forum.com/t/form-select-problem/116903/2 "2007-10-11T05:29:27Z")

</div>

Nick wrote:

> The view crashes with this error message:
> 
> ActionView::TemplateError (undefined method `merge’ for #\<Array:  
> 0x33d1b68\>) on line #110 of app/views/trail\_editor/edit.rhtml:  
> 107:   
> 108:
> 
>   
> 109: Country:  
> 110: \<%= form.select :country, :id, Country.find(:all, :order  
> =\> ‘name ASC’).map {|x| [x.name, x.id]} %\>
> 
> You want: \<%= form.select :country\_id, …
> 
> –  
> We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f9ae1b/32.png) [@nick](https://www.ruby-forum.com/u/nick)\
**Post date:** [October 11, 2007, 3:22pm UTC](https://www.ruby-forum.com/t/form-select-problem/116903/3 "2007-10-11T15:22:49Z")

</div>

Nick,  
What I can’t figure out is that you seem to try to select the STATE  
first and then select the country. This seems backwards?  
Could you digest a bit of what’s going on here?  
And thank you Mark for filling in the error.  
Thank you,  
Kathleen
