views:

52

answers:

2

Hi,

Country Model

set_table_name "countries"

has_many :states, :primary_key => 'col1', :foreign_key => 'col1'

has_many :cities, :through => :states, :primary_key => 'col1', :foreign_key => 'col1'

State Model

set_table_name "strain_appendices"  

belongs_to :country

has_many :states, :primary_key => 'col2', :foreign_key => 'col2'

City Model

set_table_name "ssu_accessions"

belongs_to :country

belongs_to :state

View

<% @countries.each do |country| %>

<%= country.high %>

<% country.states.each do |state| %>

<%= state.high %>

<% country.cities.each do |city| %>

<%= city.high %>

<%= country.high %> and <%= state.high %> give nice output. But, <%= city.high %> shows error as "uninitialized constant Country::City". Where may be the problem? Anybody help me.

A: 

Unless you define a method named high in City model or there's a high attribute, you'll get this error.

Maybe you're looking for city.country.high or city.state.high.

Edit

I'm sorry, I misread! As Shadwell said, you'd get another error in the situation described above.

j.
You'd get method missing wouldn't you? Rather than undefined constant.
Shadwell
Exactly! I'm so sorry, I misread :/
j.
A: 

In the State model, you are missing this:

has_many :cities
Phyo Wai Win
Yaa... cities missing... but, its not working with has_many :cities also...
Palani Kannan
Could you please update your question with all the required fields (col1, col2, etc) for each table and also add the end tags on the Loops as well. Thanks.
Phyo Wai Win