gpt4 book ai didi

jquery - 不要在 Ruby on Rails 6 中连接 Bootstrap 4 和 jQuery

转载 作者:行者123 更新时间:2023-12-01 08:35:40 26 4
gpt4 key购买 nike

安装了 Bootstrap 4 和 jQuery,在 DevTools 中出现错误 enter image description here

阶段安装:

1 - 执行控制台命令yarn add bootstrap@4.3.1 jquery popper.js

2 - 添加到文件 config/webpack/environment.js

const {environment} = require ('@ rails / webpacker')

const webpack = требуется ('webpack')
environment.plugins.append ('Обеспечить', новый webpack.ProvidePlugin ({
$: 'jquery',
JQuery: 'jquery',
Popper: ['popper.js', 'default']
}))

module.exports = environment

3 - 添加到文件 app/javascript/packs/application.js

import  'bootstrap' 
import '../stylesheets/application.scss'

4 - 创建文件夹 app/javascript/packs/stylesheets 并创建文件 application.scss,在其中写入 @import '~bootstrap/scss/bootstrap';

启动服务器后,在开发者面板中出现上述错误

使用过 Rails 6、Ruby 2.6.3、Windows 10

我的 gem 文件:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.3'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.0.rc1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]

end

group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

最佳答案

我发现一些潜在的问题...

  1. config/webpack/environment.js...JQuery: 'JQuery' 应为 JQuery: 'jquery'以匹配库名称。

  2. app/javascript/packs/application.js 中,您有...

    导入'./stylesheets/application.scss'

    这应该是上一级,因此请尝试将其移动到新目录...

    app/javascript/stylesheets/application.scss

    并将其更改为

    导入'../stylesheets/application.scss'

关于jquery - 不要在 Ruby on Rails 6 中连接 Bootstrap 4 和 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56435447/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com