-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flash message not set on destroy failure #61
Comments
Can you please provide a sample application that reproduces the error? |
Hi, I've set up a small test: https://github.com/michaelrigart/responder_test To simulate my error, I've overwritten the destroy model method to return false. You will notice that when you now try to destroy the object, you will get redirected back to the index. That is thanks to the location option I've set in the controller, otherwise I would get redirected to the show action. The only thing that doesn't seem right, is the fact that I get the notice flash instead of the alert . Hope this helps? |
Hey @michaelrigart. Thanks for the sample application! But you said you tried to add a base error to the resource and it didn't help, right? In this case I'm not sure what's wrong. |
Hi, thanks for pointing that out. Indeed, I've tried adding a base error ( updated the example by adding a error in the destroy method. But still the no flash message is set. |
In combination with the location option, the flash message gets lost |
Right. As you can see this commit made it using
Since this option is configurable you can easily skip it with respond_with(@post, location: posts_url, flash_now: false) |
Hi @nashby seems like setting the flash_now option to false did the trick. Thank you for pointing that out. |
However, if the default behaviour is to redirect, we should not set flash now, right? |
I got a bit confused by the quote
I don't know what the author ment by saying it is "the usual pattern" so I can't really comment on that, but I always thought that on a normal destroy action ( no ajax), the default rails behaviour is, you get either redirected to the index action on success or redirected to show on failure. So, if a redirect occurs, it seems to the flash shouldn't be set now. On the other hand, I can't see what made the author of the pull request change this. |
well, we can always ask @iain about this :) |
I think we can simply look into |
That might indeed be a cleaner way of solving this issue |
Problem seems solved. Thanks! |
This issue has come up before, but none of the solutions seem to work for me.
When I destroy a resource, I need to get redirected back to the index action ( on success and on fail ) so I use the location option.
On success, the notice flash message is set correctly.
When the destroy failed, it redirects to the index action and shows the notice flash message.
So as stated in other tickets, I added a base error on the resource through a before_destroy callback
This time I get redirected to the index action, but no flash message has been set.
Any advice?
The text was updated successfully, but these errors were encountered: