【发布时间】:2015-05-20 06:38:47
【问题描述】:
这是我第一次在这里提问。我知道我必须在这里遗漏一些非常微不足道的东西,但现在已经有一段时间无法解决了。我是 Rails 新手。
我有 4 个类,Terminal belongs_to Port,Ports belongs to_Country 和国家 belongs_to Region。
class Region < ActiveRecord::Base
has_many :countries
end
class Country < ActiveRecord::Base
belongs_to :region
has_many :ports
end
class Port < ActiveRecord::Base
belongs_to :country
has_many :terminals
end
class Terminal < ActiveRecord::Base
belongs_to :port
end
我正在尝试运行以下代码:
class TerminalsController < ApplicationController
def index
@country = Country.find_by name: 'Pakistan'
@terminals = @country.ports.terminals
end
end
我收到以下错误:
未定义的方法terminals 为#<Port::ActiveRecord_Associations_CollectionProxy:0x007fde543e75d0>
我得到以下错误:
未定义方法ports 用于<Country::ActiveRecord_Relation:0x007fde57657b00>
感谢您的帮助。
干杯,
塔哈
【问题讨论】:
标签: ruby-on-rails ruby methods undefined