Reputation: 19476
I'm trying to adjust the standard application template in Rails to insert a class around the notice and alert messages, but I can't seem to find an elegant way of doing it.
At present, I have the scaffold:
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
I want it to only show the surrounding tags if a notice or alert is present.
Upvotes: 1
Views: 2501
Reputation: 8807
<% flash.each do |name, msg| %>
<%= content_tag :div, :id => "flash_#{name}", :class => "my_class" do %>
<%= msg %>
<% end %>
<% end %>
Define styling for the .my_class
Upvotes: 1
Reputation: 528
Wrap the parts in if like this:
<% if alert %>
<p class="alert"><%= alert %></p>
<% end %>
You can also use unless
if you like
Upvotes: 0
Reputation: 139870
Use an if
statement.
<% if notice %>
<p class="notice"><%= notice %></p>
<% end %>
Upvotes: 5