undefined method `shipping_info' for #<ActiveRecord::Relation
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?
精彩评论