Hey guys, I've been struggling to integrate the toastr gem into my Rails 6 project where I already have the devise gem set up.
My main roadblock seems to be understanding webpacker and how to make toastr-rails webpacker friendly.
Despite going through all the available documentation, I still can't seem to figure it out on my own.
Here's what I've attempted so far:
yarn add toastr
Then, in my assets/packs/application.js file, I included:
@import 'toastr'
Additionally, in my assets/stylesheets/application.scss file, I required:
*= require_toastr
Lastly, in my layouts/application.html.erb file, this is the script section I added:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<% unless flash.empty? %>
<script type="text/javascript">
<% flash.each do |f| %>
<% type = f[0].to_s %>
toastr['<%= type %>']('<%= f[1] %>');
<% end %>
</script>
<% end %>
<%= yield %>
</body>
</html>
Even though this setup has worked perfectly fine in my Rails 4 project, I'm not getting any toast notifications with my current Rails 6 project.