Tuesday 15 May 2012

undefined method on Ruby on Rails 4.2` -


This is my first time asking the question. I know that I should remember something very trivial, but for a short time I have been unable to solve it. I am new to the rail.

I have 4 classes, Terminal belongs to port, port is of country and country is related area.

  square area & lt; ActiveRecord :: Base has_many: End Country Countries of country & lt; ActiveRecord :: Base is_to: The area has has_many: ports end class port & lt; ActiveRecord :: Base is_to: Country has_many: Terminal & Class Terminal & lt; ActiveRecord :: Base is_to: port end  

I am trying to run the following code:

  class terminal controller & lt; ApplicationController def index @ country = Country.find_by Name: 'Pakistan' @ terminal = @ country.port.rmynal and end  

I get the following error: Undefined method terminal # & lt; Port :: ActiveRecord_Associations_CollectionProxy: 0x007fde543e75d0>

I get the following error:

The undefined method ports for & lt; Country :: ActiveRecord_Relation: 0x007fde57657b00 & gt;

Thanks for the help.

Chair,

Taha

@ Country.ports Back to the array of ports, no terminal array has been returned, should be declared related to country model related to has_many: through .

  the square country & lt; ActiveRecord :: Base is_many: The area is has_many: The port has_many: through the terminals,: :: end of ports  

over the controller,

  class Terminal Controller & lt; ApplicationController def index @ country = Country.find_by name: 'Pakistan' @ terminal = @ country Terminal # No intermediate ports need to be terminated  

Also see:


No comments:

Post a Comment