2012-04-12 3 views
0

나는이 customer.rb모델 문제

class Customer < ActiveRecord::Base 
    acts_as_authentic 
    has_many :credit_cards 
    has_many :telephones 
    has_many :virtual_pays 
end 

telephone.rb 내가 레일을 사용하는 경우 콘솔 광고가 Customer.all 쓰기

class Telephone < ActiveRecord::Base 
    belongs_to :customers 
end 

, 난 DB 테이블에서 모든 데이터를 얻을 수 있습니다 고객,하지만 내가 모든 데이터를 가져 오려고 cutomer 전화를 포함하면 오류가 발생 작성 : 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

고객 전화 번호를 쿼리하는 방법을 알고 싶습니까? –

+0

실제로 예 .... – byCoder

답변

1

전화 모델에서는 belongs_to : customer (단수) 여야합니다.

+0

및 콘솔보다 작성하는 방법? – byCoder

+0

@pavel 콘솔이 아닌 모델에이를 쓸 것입니다. 모델에서 belongs_to : customers를 belongs_to : customer로 변경합니다. 그런 다음 콘솔을로드하고 고객 호출을 시도하십시오. –

+0

)) 알아요, 콘솔에 쓸 내용을 묻습니다. 고객. 전화 번호? 그렇다면, 작동하지 않습니다 – byCoder