NoMethodError in Devise/registrations#new

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:

<%= f.label :country %>

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”)}”})
%>


38:
39:
40:
<%= render :partial => ‘locations’, :object =>
@locations %>

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”)}”}) %>

<%= render :partial => 'locations', :object => @locations %>
<%= render :partial => 'cities', :object => @cities %>
--------------------------------------------------------------------

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

2011/2/24 Vadim A. [email protected]:

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:

<%= f.label :country %>

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

_locations.html.erb

<%= label_tag :location %>

<%= collection_select (:location_id, locations, :id, :location_name,
{:prompt => “Select an Location”}, {:onchange =>
“#{remote_function(:url => {:action => “update_cities”}, :with =>
“‘location_id=’+value”)}”}) %>

_cities.html.erb

<%= label_tag :city %>

<%= collection_select(:city_id, cities, :id, :city_name, {:prompt =>
“Select a City”}) %>

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:

<%= label_tag :location %>

2: <%= collection_select (:location_id, locations, :id,
:location_name, {:prompt => “Select an Location”}, {:onchange =>
“#{remote_function(:url => {:action => “update_cities”}, :with =>
“‘location_id=’+value”)}”}) %>

Colin L. wrote in post #983650:

On 24 February 2011 14:25, Vadim A. [email protected] 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:

<%= label_tag :location %>

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

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


<%= f.label :country %>
<%= 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")}"} %>


<%= 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

On 24 February 2011 14:25, Vadim A. [email protected] 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:

<%= label_tag :location %>

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

2011/2/25 Vadim A. [email protected]:


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

Have 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