Rails: redirect_to with :error, but flash[:error] empty

前端 未结 3 2001
孤城傲影
孤城傲影 2020-12-04 10:18

I\'m trying to do a redirect while setting the flash[:error] value. (Rails 3.0.10)

In my view I have

<%= flash[:error] %>

相关标签:
3条回答
  • 2020-12-04 10:29

    If you are having problem to keep the flash after redirecting to another path, then use this.

    flash.keep
    

    in your method, before redirecting.

    0 讨论(0)
  • 2020-12-04 10:36

    As stated in the Rails API only :notice and :alert are by default applied as a flash hash value. If you need to set the :error value, you can do it like this:

    redirect_to show_path, flash: { error: "Insufficient rights!" }
    
    0 讨论(0)
  • 2020-12-04 10:42

    To truly follow the PRG pattern, I wonder if this project works well

    https://github.com/tommeier/rails-prg

    I can't stand apps not following PRG as a user.....I have been 6 pages after a POST and hit the back button to get back to 10 pages ago get blocked by "do you want to repost this crap"....no, of course not. I just want to get back to a page I had seen before.

    non-PRG apps are very very annoying to users.

    0 讨论(0)
提交回复
热议问题