型号麻烦

问题描述:

我 customer.rb型号麻烦

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 

当我使用的轨道控制台广告写Customer.all,我会得到从数据库表中的所有数据客户,但是当我尝试获取所有数据包括客户电话我得到错误 我写:customers.telephones.all,然后我尝试Customer.Telephone.all,但如何正确地做到这一点?

NameError: undefined local variable or method 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' from /home/pp/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.9/lib/rails/commands/console.rb:8:in start' from /home/pp/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.9/lib/rails/commands.rb:23:in ' from script/rails:6:in require' from script/rails:6:in '

另外我正确的写模型?

+0

你想知道如何查询客户的电话号码吗? – 2012-04-12 20:11:56

+0

其实是的.... – byCoder 2012-04-12 21:12:54

在您的电话型号中,它应该是belongs_to:customer(单数)。

+0

和如何写在控制台? – byCoder 2012-04-13 13:26:09

+0

@pavel你会写在你的模型,而不是控制台。在您的模型中,您会将belongs_to:customers更改为belongs_to:customer。然后加载控制台并尝试您的客户呼叫。 – 2012-04-13 13:31:41

+0

))我知道,我问我应该在控制台上写什么? customer.telephones?如果是这样,它不工作 – byCoder 2012-04-13 15:37:43