I'm using Devise 4.2.1 and rendering the signup form within a Bootstrap modal. I want to be able to re-render the modal with signup errors when a user unsuccessfully tries to sign up. I was hoping there would be something like an after_unsuccessful_signup_path_for
, but haven't found anything.
I suppose I could customize the create
action within the Devise controller, but it always seems to become a super overcomplicated matter whenever I try to customize any Devise controller actions.
Is there any easy way I'm overlooking that stays away from overriding controller actions (or at least with minimal invasiveness)?
If not, what is the best way to automatically re-render this modal from the controller action?
In rails you usually have a controller that does something like this:
def create
@foo= Foo.new(foo_params)
if foo.save
redirect_to @thing
else
render template: 'new'
end
end
When the record is invalid the new
template is rendered and sent in response to the POST request. Devise is no different in this regard (just a bit more complex).
There is no after_unsuccessful_signup_path_for
since its not a resource that you can retrieve with a GET request. The "error" page is actually just the response sent from the "create" action.
If you want to display the errors in a modal you either need to send the request with ajax and update the modal or customize the devise views so that it appears as the user stayed "in the modal".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.