Rails blinks with a warning, warning, and error is not displayed; only notification is displayed

In my opinion, I have:

<% flash.now[:error] = "ERROR FLASH" %> <% flash.now[:notice] = "NOTICE FLASH" %> <% flash.now[:warning] = "WARNING FLASH" %> 

When a page receives rendering, only a blue information block appears with a FLASH NOTIFICATION. The other two will not be shown. The same thing happens with equal signs:

 <%= flash.now[:error] = "ERROR FLASH" %> <%= flash.now[:notice] = "NOTICE FLASH" %> <%= flash.now[:warning] = "WARNING FLASH" %> 

Is there a parameter in my rails application that sets a warning or errors so as not to be displayed?

+4
source share
3 answers

I had the same problem with the following code:

 redirect_to(docs_path, :warning => "I am here!!!") and return if @doc.nil? 

using ': notice' and ': alert' instead of ': warning' works as expected. It seems that you can set: notification and: notification directly in the redirect method, but not: error and: warning.

Testing for flash [: warning] .nil? the next step is true, but flash [: notice] .nil? (i.e.: warning flash not installed, but installed: notification).

To get around this, I set the flash [: warning] value before redirecting like this:

 if @doc.nil? flash[:warning] = "I am here!!!" redirect_to(docs_path) and return end 

It is not so elegant, but it works!

+7
source

Rails does nothing magical with the contents of the flash other than empty when it is supposed to.

It is entirely up to you to take appropriate measures regarding the contents of the flash memory, i.e. if you want to display an error, notification and warning, then you need to put

 <%= flash[:error] %> 

Somewhere in your view, templates or layouts where the user can see it (and repeat for: warning: notification and any other flash key that you want to display in this way)

+3
source

Please include the following in application.html.erb

 <!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script> <![endif]--> 

before:

  <%= stylesheet_link_tag "application", :media => "all" %> <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> 
-3
source

Source: https://habr.com/ru/post/1387255/


All Articles