0

我有客户.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 时,我将从数据库表客户中获取所有数据,但是当我尝试获取包括客户电话在内的所有数据时,我收到错误我写:customers.telephones.all,然后我尝试客户。 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 '来自脚本/rails:6:in require' from script/rails:6:in'

我也纠正了写模型?

4

1 回答 1

1

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

于 2012-04-12T20:11:59.513 回答