Add flash message in rails

In app/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

 
Somewhere in app/views/layouts/application.html.erb:

<%= render 'layouts/flash_messages' %> 
 
app/views/layouts/_flash_messages.html.erb

<div>
  <% flash.each do |key, value| %>
    <div class="<%= flash_class(key) %> fade in">
      <a href="#" data-dismiss="alert" class="close">×</a>
      <%= value %>
    </div>
  <% end %>
</div>

<style>
.alert {
padding: 8px 35px 8px 14px;
margin-bottom: 18px;
color: #c09853;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
background-color: #fcf8e3;
border: 1px solid #fbeed5;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}

.alert-heading {
color: inherit;
}

.alert .close {
position: relative;
top: -2px;
right: -21px;
line-height: 18px;
}



.alert-success {
color: #468847;
background-color: #dff0d8;
border-color: #d6e9c6;
}



.alert-danger,
.alert-error {
color: #b94a48;
background-color: #f2dede;
border-color: #eed3d7;
}



.alert-info {
color: #3a87ad;
background-color: #d9edf7;
border-color: #bce8f1;
}

.alert-block {
padding-top: 14px;
padding-bottom: 14px;
}


.alert-block &gt; p,
.alert-block &gt; ul {
margin-bottom: 0;
}

.alert-block p + p {
margin-top: 5px;
}


.alert-success {
color: #468847;
background-color: #dff0d8;
border-color: #d6e9c6;
}

.alert-danger,
.alert-error {
color: #b94a48;
background-color: #f2dede;
border-color: #eed3d7;
}

.alert-info {
color: #3a87ad;
background-color: #d9edf7;
border-color: #bce8f1;
}
</style>
 

 

Comments

Popular Posts

How to pass hash in Postman

nginx: unrecognized service

Bootstrap Select Picker append add new item if search not exist

Reading Excel Sheets using "Roo" gem in ruby on rails

Add CORS to Nginx on AWS Elastic Beanstalk

Enable gzip compression on Elastic Beanstalk with nginx

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

Get video duration by URL in Ruby on Rails

site-enables nginx setting in ruby in rails