Skip to content

Instantly share code, notes, and snippets.

@clauda
Last active August 8, 2016 06:50
Show Gist options
  • Save clauda/bedd3bb85db7d953f79c163bfd50a286 to your computer and use it in GitHub Desktop.
Save clauda/bedd3bb85db7d953f79c163bfd50a286 to your computer and use it in GitHub Desktop.
Toastr on Rails
...
<% unless flash.empty? %>
<script type="text/javascript">
<% flash.each do |name, message| %>
toastr['<%= flash_for(name) %>']('<%= message %>');
<% end %>
</script>
<% end %>
</body>
</html>
module ApplicationHelper
FLASH_CLASSES = {
notice: "success",
alert: "warning",
error: "error",
infod: "info"
}
def flash_for name
FLASH_CLASSES[name.to_sym]
end
...
end
application.js
`//= require toastr.min`
application.css
`*= require toastr.min`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment