Reputation: 5936
I'm having trouble with the flash messages in Rails 4. I'm doing the one month rails and when I try to login to a page or try to log out, I don't get any flash messages? Could it be the browser?
This is the code for the flash messages in application.html.erb
<% flash.each do |name, msg| %>
<% content_tag(:div, msg, class: "alert alert-#{name}") %>
<% end %>
I'm on ubuntu 14 and I'm using Firefox/Chrome
Tnx, Tom
Upvotes: 2
Views: 179
Reputation: 1430
Try this code in application layout...
<div id="wrapper">
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<% flash.each do |name, msg| %>
<%= content_tag(:div, msg, :id=>"#{name}", :class `enter code here`=> "alert alert- info") %>
<%end%>
</div>
</div>
</div>
</div>
<script type="text/javascript">
window.setTimeout(function()
{
$("#notice").fadeTo(500, 0).slideUp(500, function()
{
$(this).remove();
});
}, 5000);
</script>
<%= yield%>
Upvotes: 0
Reputation: 878
You are using the wrong erb tag, and that is why the content_tag
is not showing up. It should be:
<%= content_tag(:div, msg, class: "alert alert-#{name}") %>
Not the difference in the <%
that you had and the <%=
that I included above.
Upvotes: 5
Reputation: 766
You should use <%=
instead of <%
First one will be treated by Rails template engine as Ruby code to be executed and sent to output, while second one only be executed.
Upvotes: 1
Reputation: 10406
<%= content_tag(:div, msg, class: "alert alert-#{name}") %>
The equals is important. It tells rails to display it.
Upvotes: 1