[英]Model trouble in rails
I have customer.rb 我有customer.rb
class Customer < ActiveRecord::Base
acts_as_authentic
has_many :credit_cards
has_many :telephones
has_many :virtual_pays
end
telephone.rb 电话.rb
class Telephone < ActiveRecord::Base
belongs_to :customers
end
When I use rails console ad write Customer.all, i'll get all data from db table customers, but when i try to fetch all data include cutomer telephone i get error I write: customers.telephones.all, then i try Customer.Telephone.all, but how to correctly do this? 当我使用Rails控制台广告写Customer.all时,我将从db表客户中获取所有数据,但是当我尝试获取包括客户电话的所有数据时,我得到了错误提示: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:instart' 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:inrequire' from script/rails:6:in
' 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:inrequire' from script/rails:6:in
'
Also I correct write model? 我也正确写模型吗?
在您的电话模型中,它应该是belongs_to:customer(单数)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.