I'm working on the admin page for an application with a model called DealerBranch and a tenanted nested association called Address. I have a controller that looks like this for creating a new dealer branch:
class Admin::DealerBranchesController < Admin::AdminApplicationController
def create
@dealer_branch = DealerBranch.new(dealer_branch_attributes)
if @dealer_branch.save
render :success
else
render :new
end
end
end
When create runs it includes all of the attributes necessary to create the associated Address. However, the tenant for address is not yet created because we're building both the tenant (DealerBranch) and the associated tenanted (Address). On the line with the assignment to @dealer_branch I get the error ActsAsTenant::Errors::NoTenantSet: ActsAsTenant::Errors::NoTenantSet
What's the proper way of handling nested attributes like this?