rails和bootstrap:未捕获ReferenceError:jQuery未定义 [英] rails and bootstrap: Uncaught ReferenceError: jQuery is not defined
问题描述
我在此操作可在stackoverflow上找到,因此无需使用gem,而是在相关的应用程序目录中手动复制引导程序文件.
I created a simple webapp integrating bootstrap 3 in a rails 3.2.17 application, following this procedure found on stackoverflow, so without using a gem but manually copying the bootstrap files in the relevant app directories.
即使有,在我的gem文件中:
Even if i have, in my gem file:
gem 'jquery-rails'
在使用chrome检查我的网页时,我仍然可以看到错误:
i can still see, inspecting my web page with chrome, the error:
Uncaught ReferenceError: jQuery is not defined
我的页面是公共目录中的普通" html页面.也许不是继承"所有资产?代码是这样的:
My page is a "normal" html page in public directory. Maybe it doesn't "inherit" all the assets stuff? The code is like this:
<!DOCTYPE html>
<html>
<head>
<title>Bootsrap Test 01</title>
<link rel="stylesheet" href="/css/bootstrap.css">
<script src="/js/bootstrap.min.js" type="text/javascript"></script>
</head>
...
我还没有尝试过,但是我想基于javascript的功能将无法正常工作.
I've not yet tried but i guess that javascript based feature won't work.
推荐答案
假定添加gem 'jquery-rails'
后,您已运行bundle install
命令.
Assuming that after adding gem 'jquery-rails'
, you have ran bundle install
command.
确保您已关注app/assets/javascripts/application.js
//= require jquery
//= require jquery_ujs
//= require bootstrap.min // Add it after jquery and jquery_ujs
编辑
您需要先包含jQuery,然后再包含/bootstrap.min.js
.例如:
You will need to explicitly include jQuery before including /bootstrap.min.js
. For example :
<!DOCTYPE html>
<html>
<head>
<title>Bootsrap Test 01</title>
<link rel="stylesheet" href="/css/bootstrap.css">
<script src="/assets/jquery.js" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js" type="text/javascript"></script>
<script src="/js/bootstrap.min.js" type="text/javascript"></script>
</head>
这篇关于rails和bootstrap:未捕获ReferenceError:jQuery未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!