2010-11-26 61 views
0

我有这2种型号:未定义的方法`shipping_info”为#<的ActiveRecord ::关系

class Order < ActiveRecord::Base 
    has_one :shipping_info 
end 

class ShippingInfo < ActiveRecord::Base 
    belongs_to :order 
end 

@order = Order.new 
@order.build_shipping_info fails with NoMethodError: undefined method `build_shipping_info' for #<ActiveRecord::Relation 

任何想法,这是如何在轨道3做了什么?

编辑:其实我也在控制台得到这个:创建范围:新。覆盖现有的方法Order.new。

更新/已解决:其实我已经创建了一个新的作用域:错误新建,通过重命名作用域来解决问题。

+0

请格式化您的问题。也许你只是拼错了`@ order`到`@ oreder`? – tjeden 2010-11-26 11:53:46

+0

您显示的这段代码是正确的。所以我想这不是你真正的代码? – nathanvda 2010-11-26 12:27:37

回答

1

这个工作对我来说,如果我有这样的事情只会失败:

Order.scoped.build_shipping_info 

这是你使用的确切代码?

相关问题