简体   繁体   中英

How to flash[:notice] with redirect in rails 4 and display the notice inside a box?

I am using Rails 4 with Bootstrap 3.0.

When I save a record in respond_to do |format| block, I redirect_to the next screen with a :notice set to some value, say "Record created". This displays in the text in green. When I have some error situation, I do a flash.now[:danger] = "error occurred". This displays the message in red inside a box.

The requirement is: whether it is an error message or a regular notice, it should be displayed in a uniform fashion, except for the color change, though. In other words, I want the flash[:danger] to display text inside a box and the :notice to display in green with a box too.

I have searched a lot on google and stackoverflow but can't find any way out.

Please help!

Code:

1: format.html {redirect_to '/new', notice: 'This notice displays in green, and I want it to display green inside a box'}

  1. flash.now[:danger] = "This displays red inside a box"

Thanks a million!

I guess, I asked too fast. I saw another post not directly related to my question, but got the clue. I removed the .now in the flash command and when I do:

flash[:info] = "Notice Message" redirect_to '/new' without the :notice symbol, it displays the message inside a blue box and redirects well.

I should have mentioned in my original question that I was using flash.now.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM