我正在rails 4中开发一个测试应用程序,并希望在heroku上托管它。问题是,当我的本地系统运行良好时,我似乎无法让这些资产显示出来。
请参阅以下链接:http://depot-test.herokuapp.com/ >所有资产在文件名后面都有一些随机标识。
首先,我检查了资产在回购中实际上是可用的,它们是。
然后,我用bash检查了heroku上的资产是否可用:
$ heroku run bash
$ ls -la app/assets/images
total 60
drwx------ 2 u41129 41129 4096 2013-09-08 17:27 .
drwx------ 5 u41129 41129 4096 2013-09-08 17:27 ..
-rw------- 1 u41129 41129 15093 2013-09-08 17:27 cs.jpg
-rw------- 1 u41129 41129 0 2013-09-08 17:27 .keep
-rw------- 1 u41129 41129 1040 2013-09-08 17:27 logo.png
-rw------- 1 u41129 41129 1787 2013-09-08 17:27 rails.png
-rw------- 1 u41129 41129 9882 2013-09-08 17:27 rtp.jpg
-rw------- 1 u41129 41129 12549 2013-09-08 17:27 ruby.jpg正如你所见他们是。
然后我尝试直接加载一个映像,http://depot-test.herokuapp.com/assets/logo.png > 404
我想知道是什么导致了id被添加。
更新
哈希显然是由rails创建的,但资产仍未加载。我使用的标准rails助手如下:
image_tag
请看我的版面:
<!DOCTYPE html>
<html>
<head>
<title>Pragprog Books Online Store</title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
</head>
<body class="<%= controller.controller_name %>">
<div id="banner">
<%= image_tag("logo.png") %>
<%= @page_title || "Pragmatic Bookshelf" %>
</div>
<div id="columns">
<div id="side">
<% if @cart %>
<%= hidden_div_if(@cart.line_items.empty?, id: 'cart') do %>
<%= render @cart %>
<% end %>
<% end %>
<ul>
<li><a href="http://www....">Home</a></li>
<li><a href="http://www..../faq">Questions</a></li>
<li><a href="http://www..../news">News</a></li>
<li><a href="http://www..../contact">Contact</a></li>
</ul>
<!-- Exersise of showing current time -->
<span><%= Time.now.strftime("%I:%M:%S %z") %></span>
<!-- End showing time -->
</div>
<div id="main">
<%= yield %>
</div>
</div>
</body>
</html>发布于 2013-09-12 19:27:33
在heroku 4启动指南中,https://devcenter.heroku.com/articles/rails4#logging-and-assets声明您需要一个名为:
gem 'rails_12factor', group: :production没有这个创业板,资产管道就无法工作。这解决了我的问题。
发布于 2013-09-08 18:22:34
您看到的文件名后面的随机id是MD5指纹,它是在生产模式中添加的。这是一种破坏缓存的技术。因此,在生产模式下,您实际上不能仅通过文件名来引用资产。因此,无论您在哪里试图引用该资产,至少都需要使用asset_path。或者,如果您有一个图像,那么image_tag将为您做正确的事情。
这里有一个更好的解释为什么MD5指纹是一件好事:pipeline.html#what-is-fingerprinting-and-why-should-i-care-questionmark
以下是您必须使用的可用帮助程序的信息,以便在资产路径中包含正确的MD5指纹:pipeline.html#coding-links-to-assets
https://stackoverflow.com/questions/18686851
复制相似问题