【问题标题】:/stylesheets/application.css routing error on heroku production/stylesheets/application.css 在heroku生产中出现路由错误
【发布时间】:2015-01-24 22:31:20
【问题描述】:

不断发生应用程序错误:

2014-11-26T06:45:10.349830+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/stylesheets/application.css"):

在我的 application.html 我有:

<%= stylesheet_link_tag "application" %>

在我的 production.rb 中,因为 heroku 没有提供服务,应用程序应该提供我拥有的静态资产:

config.serve_static_assets = true
config.assets.compile = true

在我拥有的实时网站上:

<link href="/assets/application-da7e0e08bb87fbae6f1225fa189fab8e.css" media="screen" rel="stylesheet" type="text/css" />

网址

mysite/assets/application-da7e0e08bb87fbae6f1225fa189fab8e.css 

返回一个结果。

网址

mysite/assets/application.css 

也返回一个结果。

一切正常,但日志中有此错误消息,我不明白为什么。谁请求 /stylesheets/application.css 以及为什么以及如何阻止此错误发生。

Rails 是“3.2.16”

【问题讨论】:

    标签: ruby-on-rails heroku asset-pipeline


    【解决方案1】:

    应该有两个问题:

    1) 添加 %&lt;%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' =&gt; true %&gt;>

    2) 看起来您在 git 存储库中添加了资产预编译文件。理想情况下,它不应该存在,因为 heroku 可以在您推送它时为您提供。

    要解决这个问题,你必须这样做

    1. git rm -r public/assets/
    2. 在您的 .gitignore 文件中添加 public/assets/**
    3. git 添加。
    4. git commit -am "允许 heroku 自动资产预编译" 5.git push heroku master

    【讨论】:

    • 我会尝试 1) 我不想这样做 2) 因为这样 Heroku 会在每次提交时进行预编译,并且需要大约 15-20 分钟。我大约 1% 的提交与资产相关联,这就是我在本地预编译它们的方式
    猜你喜欢
    • 2013-07-19
    • 2013-09-04
    • 1970-01-01
    • 1970-01-01
    • 2023-02-16
    • 2021-07-09
    • 1970-01-01
    • 1970-01-01
    • 2017-04-26
    相关资源
    最近更新 更多