Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/52.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 钢轨模型故障_Ruby On Rails_Model - Fatal编程技术网

Ruby on rails 钢轨模型故障

Ruby on rails 钢轨模型故障,ruby-on-rails,model,Ruby On Rails,Model,我有 customer.rb class Customer < ActiveRecord::Base acts_as_authentic has_many :credit_cards has_many :telephones has_many :virtual_pays end class客户

我有 customer.rb

    class Customer < ActiveRecord::Base
    acts_as_authentic
    has_many :credit_cards
    has_many :telephones
    has_many :virtual_pays
end
class客户
电话.rb

    class Telephone < ActiveRecord::Base
    belongs_to :customers
end
class电话
当我使用rails控制台ad write Customer.all时,我将从db table customers获取所有数据,但当我尝试获取包括cutomer TENAL在内的所有数据时,我会得到错误 我写:Customer.telephones.all,然后我尝试Customer.Telephone.all,但是如何正确地做到这一点呢

NameError:未定义的局部变量或方法
customers'for
主体:客体
来自(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'
从脚本/rails:6:in
'


另外,我还要更正您的电话型号?

在您的电话型号中,它应该属于:customer(单数)

您想知道如何查询客户的电话号码?以及如何在控制台中编写电话号码?@pavel您将在您的模型中而不是控制台中编写电话号码。在您的模型中,您会将“属于:客户”更改为“属于:客户”。然后加载控制台并尝试您的客户呼叫。)我知道,我问我应该在控制台中写什么?顾客:电话?如果是这样的话,它就不起作用了。从你的评论中不清楚这一点。因为这是一对多的关系(客户有很多电话),所以我会使用Customers=Customer.all(或者更简单地说,我会这样做:Customer=Customers.first,所以我只让一个客户返回测试)。然后,在控制台中执行以下操作之一:customers[0].telephones或customer.telephones(取决于最初在控制台中键入的内容)。希望有帮助。