Flash [: notice] does not work with redirect_to

I am using controller status:

flash[:notice] = 'message' redirect_to(controller: 'item', action: 'list') 

I do not know why the notification does not appear.

I have tried and tested many things:

  • flash.keep
  • flash.keep[:notice] = 'message'
  • flash[:notice] works fine with render
  • redirect_to(controller: 'item', action: 'list', notice: 'message')
  • flash.now[:notice] = "Hello world"
  • flash.now['foo'] = "Hello world" with <%= flash['foo'] %> in the view
  • The layout has <% = flash [: notice]%>

I put the following code in the layout. flash [: notice] works fine when the controller has a view with the same name. The problem occurs when I try to contact another controller that has no view.

 <% if !flash[:notice].blank? %> <div class="notice"> <%= flash[:notice] %> </div> <% end %> <% if !flash[:alert].blank? %> <div class="alert"> <%= flash[:alert] %> </div> <% end %> 

Can anyone help?

information:

  • Ruby (2.0.0)
  • Rails (3.2.13)
+4
source share
3 answers

I do not know what happened.

I upgraded to ruby โ€‹โ€‹2.0.0 and it started working again ...

0
source

Railsguide: http://guides.rubyonrails.org/action_controller_overview.html#the-flash

This should work fine:

 flash[:notice] = "My message" redirect_to root_url 

Or:

 redirect_to root_url, notice: "Hello world" 

However, it is also possible that you forgot to make notifications in your submission. Therefore, you do not see any notifications.

For example, something like this should be in your view:

 <% if flash[:notice] %> <p class="notice"><%= flash[:notice] %></p> <% end %> 
+5
source

Try using

 flash.now['foo'] = "Hello world" 
0
source

All Articles