【发布时间】:2020-05-08 13:22:25
【问题描述】:
虽然使用 rails 运行引导程序运行良好,但 JS 功能对我不起作用。例如,我不能折叠导航栏,但我可以在浏览器控制台中运行$()。
我的 /app/javascript/packs/application.js 看起来像这样:
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
require("jquery")
require('bootstrap-sprockets')
require('popper.js')
require('turbolinks')
// As instructed in https://github.com/twbs/bootstrap-rubygem#a-ruby-on-rails
//= require bootstrap-sprockets
// But the above is not working
我的 /app/assets/stylesheets/application.scss 看起来像这样:
@import "bootstrap" ;
body {
margin: 0 ;
}
在我的 routes.rb 中,我有 root to: 'pages#home'。 home.html.erb 看起来像这样:
<div class="cover-container d-flex w-100 h-100 p-3 mx-auto flex-column">
<main role="main" class="inner cover">
<h1 class="cover-heading">Cover your page.</h1>
<p class="lead">Cover is a one-page template for building simple and beautiful home pages. Download, edit the text, and add your own fullscreen background photo to make it your own.</p>
<p class="lead">
<a href="#" class="btn btn-lg btn-secondary">Learn more</a>
</p>
</main>
<footer class="mastfoot mt-auto">
<div class="inner">
<p>Cover template for <a href="https://getbootstrap.com/">Bootstrap</a>, by <a href="https://twitter.com/mdo">@mdo</a>.</p>
</div>
</footer>
</div>
当我运行服务器并访问主页时,浏览器控制台上显示错误:
Error: Cannot find module 'bootstrap-sprockets'
我的 gem 文件有 jquery 和 bootstap 的这些条目:
gem 'jquery-rails', '~> 4.3', '>= 4.3.5'
gem "bootstrap", "~> 4.4"
gem 'bootstrap-sass'
我无法在引导程序中使用导航栏折叠等功能。怎么了?
【问题讨论】: