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 1 year has passed since last update.

Rails7でImport mapsを使ってjQuery UIを動かす

Last updated at Posted at 2022-09-01

Rails7にjqueryとjquery-ui-distをセットアップする方法を解説します。

jqueryとjquery-ui-distをピン留めする

config/importmap.rb
pin "jquery", to: "https://ga.jspm.io/npm:jquery@3.6.0/dist/jquery.js"
pin "jquery-ui-dist", to: "https://ga.jspm.io/npm:jquery-ui-dist@1.13.1/jquery-ui.js"

jqueryとjquery-ui-distをインポートする

app/javascript/application.js
import jQuery from "jquery";
window.$ = window.jQuery = jQuery;
import("jquery-ui-dist")

参考

同じ要領でJavaScriptファイルを読み込む

config/importmap.rb
pin "jquery", to: "https://ga.jspm.io/npm:jquery@3.6.0/dist/jquery.js"
pin "jquery-ui-dist", to: "https://ga.jspm.io/npm:jquery-ui-dist@1.13.1/jquery-ui.js"
+ pin_all_from 'app/javascript/custom', under: 'custom'
app/javascript/application.js
import jQuery from "jquery";
window.$ = window.jQuery = jQuery;
import("jquery-ui-dist")
+ import("./custom/***.js")

app/javascript/custom/***.jsにJavaScriptファイルを置く。

参考

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?