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:
<div id='state'>
<%= select :state, :id, Country.find(@country.id).states.map {|x|
[x.name, x.id]} %>
</div>
<%= 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| %>
<div id='state'>
<%= select :state, :id, Country.find(@country.id).states.map {|x|
[x.name, x.id]} %>
</div>
<%= 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: </tr>
108: <tr>
109: <td><label for="country">Country:</label></td>
110: <td><%= form.select :country, :id, Country.find(:all, :order
=> 'name ASC').map {|x| [x.name, x.id]} %></td>
111: </tr>
112: <tr>
113: <td><label for="trailhead_directions">Directions
to Trailhead:</label></td>
Any help would be greatly appreciated.
Thank you,