前提・実現したいこと
railsで複数画像表示機能をslickを使って実装したいのですが、
スライドになりません。どの箇所を改善すればよろしいでしょうか。。。
初歩的な質問ですいません。
発生している問題・エラーメッセージ
Uncaught ReferenceError: $ is not defined at Object../app/javascript/packs/application.js (application.js:16)
該当のソースコード
erb
1 <head> 2 <%= csrf_meta_tags %> 3 <%= csp_meta_tag %> 4 <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.18.1/build/cssreset/cssreset-min.css"> 5 <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> 6 7 <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> 8 9 <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.css"/> 10 <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick-theme.css"/> 11 12 <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script> 13 <link href="https://use.fontawesome.com/releases/v5.6.1/css/all.css" rel="stylesheet"> 14 </head>
css
1/* 2 * This is a manifest file that'll be compiled into application.css, which will include all the files 3 * listed below. 4 * 5 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's 6 * vendor/assets/stylesheets directory can be referenced here using a relative path. 7 * 8 * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS 10 * files in this directory. Styles in this file should be added after the last require_* statement. 11 * It is generally better to create a new file per style scope. 12 * 13 *= require_tree . 14 *= require_self 15 */ 16 17 @import "slick-theme"; 18 @import "slick"; 19
js
1//= require jquery 2//= require jquery_ujs 3require("@rails/ujs").start() 4//require("turbolinks").start() 5require("@rails/activestorage").start() 6require("channels") 7require('../preview') 8require('jquery') 9/*global $*/ 10 11$(function() { 12 $('.show-images').slick({ 13 dots: true, 14 }); 15});
html
1<div class ="show-images"> 2 <% post.images.each do |image| %> 3 <li class="slider"><%= image_tag image.variant(resize: '300x300') , class: 'post-image' %></li> 4 <% end %> 5</div> 6
試したこと
$ is not defined を検索し、さまざまな方法を試してもダメでした。。。
あなたの回答
tips
プレビュー