Hello, i need help. Devise + custom action in DeviseRegistrationController + dynamic select. Manual: http://pullmonkey.com/2008/3/30/dynamic-select-boxes-ruby-on-rails/ Error: -------------------------------------------------------------- NoMethodError in Devise/registrations#new Showing C:/projects/djob/app/views/devise/registrations/new.html.erb where line #37 raised: undefined method `map'' for :id:Symbol Extracted source (around line #37): 34: 35: <p><%= f.label :country %><br /> 36: <%= collection_select (:country_id, Country.all, :id, :country_name, {:prompt => "Select a Country"}, 37: {:onchange => "#{remote_function(:url => {:action => "update_locations"}, :with => "''country_id=''+value")}"}) %></p> 38: 39: 40: <div id="locations"><%= render :partial => ''locations'', :object => @locations %></div> ------------------------------------------------------------------ new.html.rb ------------------------------------------------------------------- <%= collection_select (:country_id, Country.all, :id, :country_name, {:prompt => "Select a Country"}, {:onchange => "#{remote_function(:url => {:action => "update_locations"}, :with => "''country_id=''+value")}"}) %></p> <div id="locations"><%= render :partial => ''locations'', :object => @locations %></div> <div id="cities"><%= render :partial => ''cities'', :object => @cities %></div> -------------------------------------------------------------------- registration_controller.rb --------------------------------------------------------------------- def index @countries = Country.find(:all) @locations = Location.find(:all) @cities = City.find(:all) end def update_locations # Обновляем области и города на основе выбранной страны country = Country.find(params[:country_id]) locations = country.locations cities = country.cities render :update do |page| page.replace_html ''locations'', :partial => ''locations'', :object => locations page.replace_html ''cities'', :partial => ''cities'', :object => cities end end def update_cities # Обновляем города на основе выбранной области location = Location.find(params[:location_id]) cities = location.cities render :update do |page| page.replace_html ''cities'', :partial => ''cities'', :object => cities end end -------------------------------------------------------------------------- -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2011/2/24 Vadim Antropov <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:> Hello, i need help. > Devise + custom action in DeviseRegistrationController + dynamic select. > > Manual: > http://pullmonkey.com/2008/3/30/dynamic-select-boxes-ruby-on-rails/ > > Error: > -------------------------------------------------------------- > NoMethodError in Devise/registrations#new > > Showing C:/projects/djob/app/views/devise/registrations/new.html.erb > where line #37 raised: > > undefined method `map'' for :id:Symbol > Extracted source (around line #37): > > 34: > 35: <p><%= f.label :country %><br /> > 36: <%= collection_select (:country_id, Country.all, :id, :country_name,Either that should be f.collection_select or you need an extra parameter before :country_id Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
_locations.html.erb -------------------------- <p><%= label_tag :location %><br /> <%= collection_select (:location_id, locations, :id, :location_name, {:prompt => "Select an Location"}, {:onchange => "#{remote_function(:url => {:action => "update_cities"}, :with => "''location_id=''+value")}"}) %></p> -------------------------- _cities.html.erb -------------------------- <p><%= label_tag :city %><br /> <%= collection_select(:city_id, cities, :id, :city_name, {:prompt => "Select a City"}) %></p> -------------------------- what to do with partials? new error: -------------------------- NoMethodError in Devise/registrations#new Showing C:/projects/djob/app/views/devise/registrations/_locations.html.erb where line #2 raised: undefined method `map'' for :id:Symbol Extracted source (around line #2): 1: <p><%= label_tag :location %><br /> 2: <%= collection_select (:location_id, locations, :id, :location_name, {:prompt => "Select an Location"}, {:onchange => "#{remote_function(:url => {:action => "update_cities"}, :with => "''location_id=''+value")}"}) %></p> -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 24 February 2011 14:25, Vadim Antropov <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> _locations.html.erb > -------------------------- > <p><%= label_tag :location %><br /> > <%= collection_select (:location_id, locations, :id, :location_name, > {:prompt => "Select an Location"}, {:onchange => > "#{remote_function(:url => {:action => "update_cities"}, :with => > "''location_id=''+value")}"}) %></p> > -------------------------- > > _cities.html.erb > -------------------------- > <p><%= label_tag :city %><br /> > <%= collection_select(:city_id, cities, :id, :city_name, {:prompt => > "Select a City"}) %></p> > -------------------------- > > what to do with partials? > > new error: > > -------------------------- > NoMethodError in Devise/registrations#new > > Showing > C:/projects/djob/app/views/devise/registrations/_locations.html.erb > where line #2 raised: > > undefined method `map'' for :id:Symbol > Extracted source (around line #2): > > 1: <p><%= label_tag :location %><br /> > 2: <%= collection_select (:location_id, locations, :id,You are still using the syntax for f.collection_select, but are just using collection_select. Check the docs for that method, you need an extra parameter before :location_id. See http://ap.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M000455 Colin> :location_name, {:prompt => "Select an Location"}, {:onchange => > "#{remote_function(:url => {:action => "update_cities"}, :with => > "''location_id=''+value")}"}) %></p> > > -- > Posted via http://www.ruby-forum.com/. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote in post #983650:> On 24 February 2011 14:25, Vadim Antropov <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> -------------------------- >> NoMethodError in Devise/registrations#new >> >> Showing >> C:/projects/djob/app/views/devise/registrations/_locations.html.erb >> where line #2 raised: >> >> undefined method `map'' for :id:Symbol >> Extracted source (around line #2): >> >> 1: <p><%= label_tag :location %><br /> >> 2: <%= collection_select (:location_id, locations, :id, > > You are still using the syntax for f.collection_select, but are just > using collection_select. Check the docs for that method, you need an > extra parameter before :location_id. See >http://ap.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M000455> > Colindef update_locations # Обновляем области и города на основе выбранной страны country = Country.find(params[:country_id]) locations = country.locations cities = country.cities render :update do |page| page.replace_html ''locations'', :partial => ''locations'', :object => locations page.replace_html ''cities'', :partial => ''cities'', :object => cities end end ---------------- <p><%= f.label :country %><br /> <%= f.collection_select :country_id, Country.all, :id, :country_name, {:prompt => "Select a Country"}, {:onchange => "#{remote_function(:url => {:action => "update_locations"}, :with => "''country_id=''+value")}"} %></p> ------------------ <%= collection_select(nil, :location_id, locations, :id, :location_name, {}, {:prompt => "Select an Location"}, {:onchange => "#{remote_function(:url => {:action => "update_cities"}, :with => "''location_id=''+value")}"}) %> -------------------- NoMethodError in Devise/registrations#new Showing C:/projects/djob/app/views/devise/registrations/_locations.html.erb where line #1 raised: You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.map -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2011/2/25 Vadim Antropov <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:> ... > ------------------ > <%= collection_select(nil, :location_id, locations, :id, :location_name, > {}, > {:prompt => "Select an Location"}, > {:onchange => "#{remote_function(:url => {:action > => "update_cities"}, > :with => > "''location_id=''+value")}"}) %> > > -------------------- > > NoMethodError in Devise/registrations#new > > Showing > C:/projects/djob/app/views/devise/registrations/_locations.html.erb > where line #1 raised: > > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.mapHave a look at the Rails Guide on debugging. Then set breakpoint in the view code just before the error and inspect the data to see if it all looks right. First though I would check the docs for collection_select and check that nil is valid as the first parameter. Note particularly in http://ap.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M000455 the second sentence and what it says about the object parameter. I suspect you have another problem with one of the other params that is causing the map problem. Perhaps one of them is nil also. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.