[英]Rails trying to load assets from incorrect locations
我的javascript和jquery有问题。 除了一些自行编写的脚本之外,我还在使用引导程序。 当我尝试执行JavaScript驱动的操作(即单击显示隐藏的div的按钮或打开模式)时,浏览器不响应。 浏览器的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
请注意,该位置在文件夹“ ecns”中,而不是在“ assets”中。 Ecns是我的模型之一,是我当前在浏览器中使用的模型,如果我转到应用程序的其他部分,则错误如下所示:
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/requests/js/bootstrap.min.js
我知道脚本本身没有问题,因为它们可以在不同的计算机上工作。 我假设我在滑轨中配置或安装不正确。 供参考,这是我的application.js:
//= require jquery
//= require jquery_ujs
//= require_tree .
以下是我的应用程序布局:
<head>
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<title>Site</title>
<%= javascript_include_tag "application" %>
<%= stylesheet_link_tag "application", media: "all" %>
<%= csrf_meta_tags %>
</head>
<body>
...
<script src="js/bootstrap.min.js"></script>
</body>
为什么Rails会寻找资产的不正确位置? 我正在运行Rails 3.2.1
Rails是使用自定义资产管道,这将使下的所有资产,可见assets
在应用程序的根目录下创建子目录。
因此,如果您的基本地址为http://www.something.com/
所有资产都将位于http://www.something.com/assets/
下。
如果要导入CSS或JS文件,并且将它们正确放置在Rails的app/assets/
目录中,则应使用以下命令:
<%= javascript_include_tag "bootstrap.min" %>
<%= stylesheet_link_tag "bootstrap.min" %>
将它们放置在布局中所需的任何位置。
如果您仍然想手动导入它们(我不建议这样做),请使用以下命令:
<script src="assets/bootstrap.min.js"></script>
<link href="assets/bootstrap.min.css" rel="stylesheet" media="screen">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.