Josh,
This is exactly what I am trying to do with Rails 3.1 and Devise 1.48. Did you get it to work?
One thing you might need is to add :account_attributes to your attr_accessible.
However, I'm not even sure that
accepts_nested_attributes_for will work this way. If I understand correctly, that is supposed to go on the
parent model, in this case Account. I've tried putting it on the User model as you have, then running the following RSpec test (in spec/models/user_spec.rb):
it "should work with accepts_nested_attributes_for" do
@userwithaccount = { :email => "FakeEmailForGroup",
:password => "testpass",
:account_attributes => { :name => "Test Account" } }
User.create!(@userwithaccount)
end
That fails with "ActiveRecord::RecordInvalid: Validation failed: Account can't be blank".
My hunch is that accepts_nested_attributes_for tries to create the "local" model first, assuming it is the parent, then tries to link the "foreign" model to it. So it's trying to create the User object, but it can't because User requires a link to Account, i.e. Account must be created first.
Seems like if it doesn't work at the model level from a test, it's not going to work from a form.
Any further info on how to solve this would be appreciated!
Thanks,
Mark Berry