[英]Rails: Jquery/Javascript fails to load from correct assets location
我的Jquery和Javascript出现问题。 我一直在构建一个应用程序,使用github在工作和家庭之间进行处理。 在工作中,一切正常,我的所有Jquery工作正常。 当我在家拉应用程序时,jquery和javascript无法响应。 这包括我从引导程序使用的javascript。
浏览器的javascript控制台显示了一些错误,这些错误似乎是问题的根源,但我不确定如何解决这些错误。
我的应用程序布局包括:
<head>
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<title>Website</title>
<%= javascript_include_tag "application" %>
<%= stylesheet_link_tag "application", media: "all" %>
<%= csrf_meta_tags %>
</head>
...
<body>
...
<script src="/js/bootstrap.min.js"></script>
</body>
而我的application.js具有:
//= require jquery
//= require jquery_ujs
//= require_tree .
//= require bootstrap.min.js
我还应该检查或尝试更改什么?
我的浏览器JavaScript控制台也会引发一些错误:
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/requests/css/bootstrap.min.css
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/requests/js/bootstrap.min.js
请求是我的模型之一。 根据我当前使用的mvc,它将在那些文件夹中搜索资源。 例如,当我尝试使用“ ecn”视图中的javascript时,出现以下错误:
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/ecns/css/bootstrap.min.css
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/ecns/js/bootstrap.min.js
为什么Rails会尝试在资产文件夹以外的任何文件夹中寻找资产?
首先,您应该在应用程序布局中删除<script src="/js/bootstrap.min.js"></script>
,因为您的application.js
已经包含bootstrap.min.js
(正是这一行: //= require bootstrap.min.js
),因此无需添加两次,对于此行<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
它。
第二件事是您从控制台获取的错误:
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/requests/css/bootstrap.min.css
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/requests/js/bootstrap.min.js
看来您的应用程序尝试从名为requests/js
和requests/css
的文件夹中加载bootstrap.min.js
和bootstrap.min.css
,您已经这样的文件夹了吗? 我认为如果您使用Rails> = 3的话,bootstrap generator将使用/app/assets
目录,正好是app/assets/javascripts/
和app/assets/stylesheets/
我认为这个railscast Twitter Bootstrap Basics也可以为您提供帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.