Replace rails flash messages with toastr

1. set up toastr
2. add the following code to application.html.erb

<% unless flash.empty? %>
  <script type="text/javascript">
      <% flash.each do |f| %>
      <% type = f[0].to_s.gsub('alert', 'error').gsub('notice', 'info') %>
     toastr['<%= type %>']('<%= f[1] %>');
      <% end %>
  </script>
<% end %>

 

Leave a Reply

Your email address will not be published.