1
3

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 5 years have passed since last update.

iQueryの$でis not defined;をはかれた時の対処法

1
Posted at

「$」マークでエラーが出た時の対処法。

app/assets/javascripts/ファイル名.js
にjQueryで記述する際の最初に使う「$」マークでエラーが出た時は実は簡単に消せます。
スクリーンショット 2019-08-22 10.43.19.png

前提として、app/assets/javascripts/application.jsには


//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require rails-ujs
//= require bootstrap
//= require activestorage
//= require turbolinks
//= require_tree .

これらが書かれてるものとします。
注意: require_tree.は一番最後の記述にしてください。

解決方法

エラー画面にもある**add /* global $*/**を上にそのまま追加することによってエラーは消えます。
スクリーンショット 2019-08-22 10.54.21.png

他にも解決策があると思いますが自分でこれで解決したので投稿させていただきます。
誰かの助けになれば幸いです。

1
3
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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?