Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Flash message not set on destroy failure #61
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.
respond_with(@resource, location: resources_url)
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.
This time I get redirected to the index action, but no flash message has been set.
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.
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)
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.