簡體   English   中英

導軌中的模型故障

[英]Model trouble in rails

我有customer.rb

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

電話.rb

    class Telephone < ActiveRecord::Base
    belongs_to :customers
end

當我使用Rails控制台廣告寫Customer.all時,我將從db表客戶中獲取所有數據,但是當我嘗試獲取包括客戶電話的所有數據時,我得到了錯誤提示: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 /console.rb:44:從/home/pp/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.9/lib/rails/commands/console.rb:8開始: start' from /home/pp/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.9/lib/rails/commands.rb:23:in '從腳本/ rails:6:in require' from script/rails:6:in '

我也正確寫模型嗎?

在您的電話模型中,它應該是belongs_to:customer(單數)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM