class Customer < ActiveRecord::Base
acts_as_authentic
has_many :credit_cards
has_many :telephones
has_many :virtual_pays
end
telephone.rb
class Telephone < ActiveRecord::Base
belongs_to :customers
end
当我使用rails控制台广告写Customer.all时,我将从db表客户那里获取所有数据,但当我尝试获取所有数据时包括cutomer电话我得到错误 我写:customers.telephones.all,然后我尝试Customer.Telephone.all,但是如何正确地做到这一点?
NameError:未定义的局部变量或方法
customers' for main:Object from (irb):6 from /home/pp/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.9/lib/rails/commands/console.rb:44:in
start' 来自/home/pp/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.9/lib/rails/commands/console.rb:8:instart' from /home/pp/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.9/lib/rails/commands.rb:23:in
” 来自script / rails:6:require' from script/rails:6:in
'
我也正确写模型?
答案 0 :(得分:1)
在您的电话型号中,它应该是belongs_to:customer(singular)。