style.js をindex.htmlで読み込みたいのですが、うまく読み込みません。
解決策が分かる方いらっしゃればお願いいたします。
#app/views/pages/index.html.erb <div class="container"> <div class="row"> <div id="menu" class="col-sm-3"> </div><!-- side-menu --> <div id="main-content" class="col-sm-9"> <%= render @posts %> </div><!-- main-content --> </div><!-- row --> </div><!-- container -->
#app/views/layouts/application.html.erb <!DOCTYPE html> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script> <html> <head> <title>Collabfield</title> <%= csrf_meta_tags %> <%= csp_meta_tag %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> </head> <body> <%= render 'layouts/navigation' %> <%= yield %> </body> </html>
#app/assets/javascript/posts/style.js $(document).on('turbolinks:load', function() { if ($(".single-post-card").length) { if (mode == 1) { $(".single-post-card").each(function() { $(this).addClass("solid-color-mode"); $(this).css('background-color', randomColor()); }); } else { $(".single-post-card").each(function() { $(this).addClass("border-color-mode"); $(this).css('border', '5px solid ' + randomColor()); }); } } $('#feed').on( 'mouseenter', '.single-post-list', function() { $(this).css('border-color', randomColor()); }); $('#feed').on( 'mouseleave', '.single-post-list', function() { $(this).css('border-color', 'rgba(0, 0, 0, 0.05)'); }); }); var colorSet = randomColorSet(); var mode = Math.floor(Math.random() * 2); function randomColorSet() { var colorSet1 = ['#45CCFF', '#49E83E', '#FFD432', '#E84B30', '#B243FF']; var colorSet2 = ['#FF6138', '#FFFF9D', '#BEEB9F', '#79BD8F', '#79BD8F']; var colorSet3 = ['#FCFFF5', '#D1DBBD', '#91AA9D', '#3E606F', '#193441']; var colorSet4 = ['#004358', '#1F8A70', '#BEDB39', '#FFE11A', '#FD7400']; var colorSet5 = ['#105B63', '#FFFAD5', '#FFD34E', '#DB9E36', '#BD4932']; var colorSet6 = ['#04BFBF', '#CAFCD8', '#F7E967', '#A9CF54', '#588F27']; var colorSet7 = ['#405952', '#9C9B7A', '#FFD393', '#FF974F', '#F54F29']; var randomSet = [colorSet1, colorSet2, colorSet3, colorSet4, colorSet5, colorSet6, colorSet7]; return randomSet[Math.floor(Math.random() * randomSet.length )]; } function randomColor() { var color = colorSet[Math.floor(Math.random() * colorSet.length)]; return color; }
<script src="style.js"></script>をapplication.html.erbに挿入してみたり、chromeの検証でエラーを探しましたが分かりませんでした。spec/rails_helper.rb . . . config.include Devise::Test::IntegrationHelpers, type: :feature config.include FactoryBot::Syntax::Methods Capybara.javascript_driver = :selenium_chrome_headless Capybara.server = :puma
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。