Mongoid Embeds_many won't save on nested form
- by Brandon J McKay
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?