Search code examples
ruby-on-railsrubyflash-message

avoiding application.html.erb for flash notices on rails app landing page


I have designed two flash notices for my rails 4 application. First is supposed to appear on all pages (when an event occurs), so I have written it in my application.html.erb file. The second one should only appear on the landing page with its custom CSS.

Right now, both are showing on the landing page. How can I avoid first one (written in application.html.erb) only for my landing page?


Solution

  • If you want to avoid rendering your flash notices for particular controller or action, then you can do something like this -

    <% unless params[:action] == 'something' %>
      <% flash.each do |key, value| %>
        <div class="alert alert-<%= key %>"><%= value %></div>
      <% end %>
    <% end %>