Hi
I have another question for how best to do this. Now I have been
following the tutorial at:
http://www.tunaslut.com/learning-ruby-drop-down-lists-in-one-to-many-relationships,
however when I change the view over from
<% @cities.each do |city| %>
<%=h city.city_name %>
<%=h city.country_id %>
to:
<% @cities.each do |city| %>
<%=h city.city_name %>
<%=h city.country.country_name %>
The system breaks with the following error
NoMethodError in Cities#index
Showing app/views/cities/index.html.erb where line #12 raised:
undefined method `country_name’ for nil:NilClass
Extracted source (around line #12):
when attempting to display data on cities
My questions are:
- Is there an easier way of doing drop down boxed populated from a
table?
- is this foreign key assignment working?
- is this a good way of doing FK asignments? is there a better way.
Please forgive me, I’m old school, more used to the SQL statements…
Thanks again.
disruptive tech wrote:
Hi
I have another question for how best to do this. Now I have been
following the tutorial at:
http://www.tunaslut.com/learning-ruby-drop-down-lists-in-one-to-many-relationships,
however when I change the view over from
<% @cities.each do |city| %>
<%=h city.city_name %>
<%=h city.country_id %>
to:
<% @cities.each do |city| %>
<%=h city.city_name %>
<%=h city.country.country_name %>
The system breaks with the following error
NoMethodError in Cities#index
Showing app/views/cities/index.html.erb where line #12 raised:
undefined method `country_name’ for nil:NilClass
…which means that city.country is nil. You have to make it not be.
Extracted source (around line #12):
when attempting to display data on cities
My questions are:
- Is there an easier way of doing drop down boxed populated from a
table?
collection_select
- is this foreign key assignment working?
- is this a good way of doing FK asignments? is there a better way.
I don’t see any assignment in your code.
Please forgive me, I’m old school, more used to the SQL statements…
What’s that got to do with anything?
Thanks again.
Best,
Marnen Laibow-Koser
http://www.marnen.org
[email protected]