I have a model like this
class Canvas
include Mongoid::Document
field :name
referenced_in :hero
end
class Browser < Canvas
field :version, :type => Integer
end
class Hero
include Mongoid::Document
field :name
references_many :canvases
end
How can I build Brower Object refered from Hero object.
All i want to do is
h = Hero.create!({:name => 'Aston'})
h.browsers.build
However it gave me an error
undefined method `browsers' for #<Hero _id: 4d92c8fc1426960fff000005, name: "Aston">
Am i missing something?
Thanks
try this
h.canvases.build({},Browser)
this works for mongoid.2.0.0.rc7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With