Add jquery in rails by self ::: Add the Jquery in Rails 6 and check / test it is working or not by step 3 ::: Full proof code :: do not see anything else

Step 01 ::

$  yarn add jquery

Step 02 ::

const { environment } = require('@rails/webpacker')

inside   environment.js

const webpack = require('webpack')

environment.plugins.prepend('Provide',

  new webpack.ProvidePlugin({

    $: 'jquery/src/jquery',

    jQuery: 'jquery/src/jquery'

  })

)

module.exports = environment

Note :: Inside the bold content just add the Italic Content 

Step 03 :: Testing  of the Jquery :: If Jquery is added or not 

 Add the below code inside file you want to check 

<!DOCTYPE html>

<html lang="en">

<head>

<script src=

"https://code.jquery.com/jquery-3.6.0.min.js"

integrity=

"sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="

crossorigin="anonymous">

</script>

</head>

<body>

<button id="btn">Click me!</button>

<script>

$(document).ready(function () {

$("#btn").click(function () {

alert("This is an alert message!");

});

});

</script>

</body>

</html>

Comments

Popular posts from this blog

Rails 7 Features :: Comparison with Rails 6 and Rails 5