Introduced Rails6 toastr

Introduction

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

Installation procedure

** 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! 8FAC511B-E1CB-4ED1-9B95-BE2A731045FA_1_105_c.jpeg

Recommended Posts

Introduced Rails6 toastr
Rails6 jQuery introduced
Rails Bootstrap introduced
[Rails] Introduced debugging gems'better_errors' and'binding_of_caller'
Introduced gRPC client to rails
[Ruby on Rails] Introduced paging function
[Rails g.error]
Rails Review 1
Rails API
Rails migration
Introduced jacoco
[Rails] first_or_initialize
About Rails 6
Introduced Vue.js to an existing Rails app
Rails foundation
Rails memorandum
rails tutorial
rails tutorial
rails tutorial
[Rails] devise
rails tutorial
rails tutorial
Rails Tips
rails method
rails tutorial
How to use credentials.yml.enc introduced in Rails 5.2
Introduced Vuetify to an existing Rails app
[Rails] ActiveRecord
[Rails] form_with
Rails Review 2