After a user signs up to my Rails 3.2.3 app which uses Devise, an after_create callback is triggered which attempts to create an Organisation record.
If this create fails validation, how can I get the error messages to display? Should I override the devise controller? Thing is, the errors are related to the creation of an Organisation, not a User (and I have a pretty vanilla devise User model set-up).
I’m doing something like this in the User model:
# after_create callback method
...
unless new_org_user.save
errors.add("Warning", "Organisation is invalid" )
end
...
Since you are firing the event in the after_create callback the record is already successfully created so no flash message will apear.
Why dont you try to move it to relation association instead and require validation of child like
This way if organization is not valid it will fail the validation