1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Rails]jqueryの導入

Posted at

アプリ開発でjqueryを使うことが多かったので、導入方法をまとめました。
Railsのバージョンは6.0.0です。

ターミナル
yarn add jquery
config/webpack/environment.js
const { environment } = require('@rails/webpacker')
# 追記
const webpack = require('webpack')
environment.plugins.prepend('Provide',
    new webpack.ProvidePlugin({
        $: 'jquery/src/jquery',
        jQuery: 'jquery/src/jquery'
    })
)
# ここまで
module.exports = environment
app/javascript/packs/application.js
require('jquery')  # 追記
require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
require("../category")
require("../category_post")
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?