KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have two models: user and company. They both get created from one form and I'm using a transaction like this: User.transaction do @user.save! @company.user = @user @company.save! @user.reload @user.company = @company @user.save! flash[:notice] = "Thank you for your registration." redirect_to_index end The user gets saved to the database even when one of the company's validations fails. I've tried adding explicit error handling of ActiveRecord::RecordInvalid but it didn't help. I thought the validation would raise the error to rollback the transaction anyway. Any help is greatly appreciated. Thanks
Tags (comma-separated)
Save Edits
Cancel