I introduced toastr
in Rails 6
, so I will make a note of it.
Here, we will proceed in the process that jQuery
has already been introduced.
References https://medium.com/@ranl_51760/get-toastr-working-on-rails-6-with-webpack-in-steps-5ca1ac8594e0
** Install toastr **
Terminal
yarn add toastr
** Add the following to config/initializers/assets.rb **
config/initializers/assets.rb
Rails.application.config.assets.paths << Rails.root.join('node_modules')
Rails.application.config.assets.precompile += ['node_modules/toastr/build/toastr.min.js']
Rails.application.config.assets.precompile += ['node_modules/toastr/build/toastr.min.css']
Added the following to ** app/javascript/packs/application.js **
app/javascript/packs/application.js
import './src/application.scss'
import toastr from 'toastr'
window.toastr = toastr
Create ** app/javascript/packs/src/application.scss ** and write the following
app/javascript/packs/src/application.scss
@import 'toastr/build/toastr.min';
Describe the following in ** html file **
html file
<script type="text/javascript">
toastr.success("hello")
</script>
I was able to display it like this!
Recommended Posts