Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happened to the flash messages in Rails 3.2.1?

I use this code to display flash messages in Rails 3.2.1 apps (well, I did):

<% flash.each do |name, msg| %>
    <div class="alert alert-<%= name == :notice ? "success" : "error" %>">
        <%= msg %>
    </div>
<% end %>

But I get nothing. So I put <%= debug flash %> to see what I was getting back after an update and I get this:

--- !ruby/object:ActionDispatch::Flash::FlashHash
used: !ruby/object:Set
  hash: {}
closed: false
flashes: {}
now: 

How to I do the same thing?

like image 822
cbmeeks Avatar asked Dec 04 '25 16:12

cbmeeks


1 Answers

The code I use for displaying flash messages and alerts is:

<% flash.each do |name, msg| %>
  <%= content_tag :div, msg, :class => "flash flash_#{name}" %>
<% end %>

But if your flash hash is empty, it's not going to display anything. Are you sure you're setting your flash hash properly?

like image 70
admpsktt Avatar answered Dec 07 '25 00:12

admpsktt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!