Reputation: 136
I'm using from controller status:
flash[:notice] = 'message'
redirect_to(controller: 'item', action: 'list')
I don't know why the notice don't show up.
I tried and checked 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 viewI put the following code to in the layout. flash[:notice] work fine when I the controller method have a view with the same name. The problem happens when I try to reach another controller which don't have a 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?
Info:
Upvotes: 4
Views: 1720
Reputation: 136
I have no idea about what happened.
I updated to ruby 2.0.0 and it just started to work again...
Upvotes: 0
Reputation: 2399
Railsguide: http://guides.rubyonrails.org/action_controller_overview.html#the-flash
This should work perfectly fine:
flash[:notice] = "My message"
redirect_to root_url
Or:
redirect_to root_url, notice: "Hello world"
However, it could also be possible you forgot to render notices in your view. Hence, you don't see any notices whatsoever.
For example, something like this should be in your view:
<% if flash[:notice] %>
<p class="notice"><%= flash[:notice] %></p>
<% end %>
Upvotes: 5