cjm2671
cjm2671

Reputation: 19476

How do I change notice & alert's class?

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

Answers (3)

Syed Aslam
Syed Aslam

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

iwg
iwg

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

hammar
hammar

Reputation: 139870

Use an if statement.

<% if notice %>
    <p class="notice"><%= notice %></p>
<% end %>

Upvotes: 5

Related Questions