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,
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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: </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>You want: <%= form.select :country_id, ... -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Oct-11  13:21 UTC
Re: form.select problem
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 On Oct 10, 5:04 pm, Nick <nhi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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,--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---