Mongoid Embeds_many won't save on nested form
Posted
by
Brandon J McKay
on Stack Overflow
See other posts from Stack Overflow
or by Brandon J McKay
Published on 2012-10-30T10:59:03Z
Indexed on
2012/10/30
11:00 UTC
Read the original article
Hit count: 252
I've got an embeds_many association I'm trying to set up which I've done successfully before, but I'm trying to do it all in one nested form and I can't figure it out.
Let's say we have a pocket
model:
class Pocket
include Mongoid::Document
field :title, type: String
embeds_many :coins, cascade_callbacks: true
end
and a Coin Model:
class Coin
include Mongoid::Document
field :name, type: String
embedded_in :pocket
end
in my form for the pocket, I'm using:
= f.fields_for @pocket.coins do |coin|
= coin.text_field :name
My controller is the default scaffolded controller. When I use the console, it saves fine and I can see the new pocket and coin I've created. But when I try to create or update a coin from the form, the pocket saves but the coin remains unchanged.
What am I missing here?
© Stack Overflow or respective owner