I have implemented an application helper to dynamically provide the class of a flash message to the view for styling with Bootstrap. The setup works but along with the ERB, the actual parameters hash is being output to the view. I have look at all of my application code in the helpers and views and can’t pinpoint the source. I’ve also looked at the output HTML and it was not indicative of the source problem. Below are the helpers and views as well as a snapshot of the troubled output result.
Troubled View Output
http://screencast.com/t/9KZHxjqm1Pq
—
# layouts/application.html.erb
...
</head>
<body>
<%= render "layouts/header" %>
<div class="container">
<% if flash.any? %>
<%= render 'shared/flash_messages' %>
<% end %>
<%= yield %>
...
—
# views/shared/_flash_messages.html.erb
<div>
<%= flash.each do |key, value| %>
<div class="<%= flash_class(key) %> fade in">
<a href="#" data-dismiss="alert" class="close">x</a>
<%= "#{value}" %>
<% end %>
</div>
</div>
—
# helpers/application_helper.rb
module ApplicationHelper
def flash_class(level)
case level
when :notice then "alert alert-info"
when :success then "alert alert-success"
when :error then "alert alert-error"
when :alert then "alert alert-error"
end
end
end
It’s because you are doing
So the result of
eachis displayed, as well as anything produced by the block. Change the <%= to <%