开发者

undefined method `shipping_info' for #<ActiveRecord::Relation

开发者 https://www.devze.com 2023-01-27 15:08 出处:网络
I have these 2 models: class Order < ActiveRecord::Base has_one :shipping_info end class ShippingInfo < ActiveRecord::Base

I have these 2 models:

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 #<ActiveRecor开发者_运维问答d::Relation

Any idea how this is done in rails 3 ?

EDIT: Actually I also get this in the console: Creating scope :new. Overwriting existing method Order.new.

UPDATE/SOLVED: Actually I've created a new scope named :new by mistake, problem fixed by renaming the scope.


This works for me, and would only fail if I had something like this:

Order.scoped.build_shipping_info

Is this the exact code you're using?

0

精彩评论

暂无评论...
验证码 换一张
取 消