I have a parent model called Account that has a Company.
The Account model uses the accepts_nested_attributes_for :company helper.
I’m using a RESTful approach to creating an Account, that will / should also create a Company.
In my new action for the AccountsController, I have:
@account = Account.new
@company = @account.companies.new
When I fire up the new view, I can see both the account object and the company object using the <%= debug... %> function in the view.
In my create action for the AccountsController, I render 'new' if validation does not pass.
Here’s what’s confusing me:
When render 'new' is invoked, I no longer see the company object, but only the account object.
Where did the company object go and how do I get it back so I can access it?
Thank you.
The method “create” must contain the line with “@company = @account.companies.new” if validation does not pass.