質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

671閲覧

Uncaught ReferenceError: jQuery is not defined at

teruya_inomata

総合スコア14

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2019/11/27 12:44

https://gyazo.com/d077407d76c9bcbf716a212648ea6171
このようなブログを作っており、グレー、カメラ部分をタッチするとフォルダが、開けるような機能を実装しようとしています。

しかし、Uncaught ReferenceError: jQuery is not defined at というエラーがクロームのコンソールを調べるとでできます。これは、ジェークエリーが、読み込まれていない、定義されていないことだと検索などで分かりました。
<%= form_for article do |f| %>

<div id="cover-image" class="form-group padding-top-15 relative"> <%= image_tag 'grey-bg.jpg', class: 'article-image' %> <i class="fa fa-camera"></i> </div>
<%= f.attachment_field :image %>
<div class="form-group padding-bottom-15"> <%= f.label :title, 'タイトル' %> <%= f.text_field :title, class: 'form-control' %> </div> <div class="form-group"> <%= f.label :body, '本文' %> <%= f.text_area :body, rows: 10, class: 'form-control' %> </div> <%= f.submit class: 'btn btn-success' %> <% end %> ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー $ -> $('#cover-image').click -> $('#article_image').click() false コードはこちらです。 誤字がないか、記述ミスがないか、検索などで、あれこれ一時間半くらい経ちましたが、分かりません。 ご教授お願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

maisumakun

2019/11/27 13:00

JavaScriptの読み込み部分はどこでしょうか。
teruya_inomata

2019/11/27 13:09

コメントありがとうございます。 cable.js // Action Cable provides the framework to deal with WebSockets in Rails. // You can generate new channels where WebSocket features live using the `rails generate channel` command. // //= require action_cable //= require_self //= require_tree ./channels (function() { this.App || (this.App = {}); App.cable = ActionCable.createConsumer(); }).call(this); application.js // This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's // vendor/assets/javascripts directory can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // compiled file. JavaScript code in this file should be added after the last require_* statement. // // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details // about supported directives. // //= require rails-ujs //= require activestorage //= require turbolinks //= require bootstrap-sprockets //= require_tree . jsはこんな感じなのですが、なぜエラーが出るのかが分かりません、、、
maisumakun

2019/11/27 13:19

jQueryの読み込み部分はどこでしょうか?
teruya_inomata

2019/11/27 13:27

# Place all the behaviors and hooks related to the matching controller here. # All this logic will automatically be available in application.js. # You can use CoffeeScript in this file: http://coffeescript.org/ $ -> $('#cover-image').click -> $('#article_image').click() false ここですか?ですがここはjsですよね?
guest

回答1

0

ベストアンサー

jsはこんな感じなのですが、なぜエラーが出るのかが分かりません、、、

おそらく、jQuery本体を読み込んでいないからだと思われます。

投稿2019/11/27 13:28

maisumakun

総合スコア145184

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

teruya_inomata

2019/11/27 13:31

かしこまりました!!ありがとうございます。新たにfileを作成したら良いのでしょうか。動画学習ですが、coffee script 以外記述していませんでした,,,,,
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問