【问题标题】:Heroku asset pre compile locally did not show on herokuHeroku 资产本地预编译未显示在 Heroku 上
【发布时间】:2018-04-28 00:46:49
【问题描述】:

在本地对资产进行了几次测试并使用生产环境在本地预编译后,我决定部署到 Heroku。但首先我从公用文件夹提交和部署中删除了资产。

部署图片后,css和javascript没有显示在heroku上。

我试过在终端上预编译,也没有显示出来。

我搜索了 heroku 文档,但没有找到任何相关内容。

知道heroku的人可以帮忙吗?

rake assets:precompile RAILS_ENV=production on ⬢ app... up, run.6445 (Free)
Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install

I, [2018-04-28T00:34:53.297091 #4]  INFO -- : Writing /app/public/assets/application-6530ec3783a5066dace59576978030c61110e689042a33aaabfa02bab8729a22.js
I, [2018-04-28T00:34:53.298286 #4]  INFO -- : Writing /app/public/assets/application-6530ec3783a5066dace59576978030c61110e689042a33aaabfa02bab8729a22.js.gz
I, [2018-04-28T00:34:53.404455 #4]  INFO -- : Writing /app/public/assets/application-888a5e4ac602e29fa84543f0d08fdf1f1f8821de0be9809aabb90dd2b5ac27ad.css
I, [2018-04-28T00:34:53.405133 #4]  INFO -- : Writing /app/public/assets/application-888a5e4ac602e29fa84543f0d08fdf1f1f8821de0be9809aabb90dd2b5ac27ad.css.gz







2018-04-28T01:02:42.479552+00:00 app[web.1]: [d7e41abe-2ebd-45bd-837f-04c140203f42] vendor/bundle/ruby/2.3.0/gems/rack-2.0.5/lib/rack/sendfile.rb:111:in `call'
2018-04-28T01:02:42.479553+00:00 app[web.1]: [d7e41abe-2ebd-45bd-837f-04c140203f42] vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/engine.rb:522:in `call'
2018-04-28T01:02:42.479555+00:00 app[web.1]: [d7e41abe-2ebd-45bd-837f-04c140203f42] vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/lib/puma/configuration.rb:225:in `call'
2018-04-28T01:02:42.479556+00:00 app[web.1]: [d7e41abe-2ebd-45bd-837f-04c140203f42] vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/lib/puma/server.rb:632:in `handle_request'
2018-04-28T01:02:42.479576+00:00 app[web.1]: [d7e41abe-2ebd-45bd-837f-04c140203f42] vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/lib/puma/server.rb:446:in `process_client'
2018-04-28T01:02:42.479578+00:00 app[web.1]: [d7e41abe-2ebd-45bd-837f-04c140203f42] vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/lib/puma/server.rb:306:in `block in run'
2018-04-28T01:02:42.479579+00:00 app[web.1]: [d7e41abe-2ebd-45bd-837f-04c140203f42] vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/lib/puma/thread_pool.rb:120:in `block in spawn_thread'
2018-04-28T01:02:42.427445+00:00 heroku[router]: at=info method=GET path="/assets/sqre-14c09561486ba385a8a62bc0a8b41e03638a6334648113a7f28be47271eccb5e.png" host=app.herokuapp.com request_id=bce0c62c-3568-44e4-adeb-74ed17691890 fwd="186.237.160.170" dyno=web.1 connect=1ms service=3ms status=404 bytes=1902 protocol=https
2018-04-28T01:02:42.480067+00:00 heroku[router]: at=info method=GET path="/assets/iore-583714033cab0d76045a8d4bbfb2326983f40d5c2cfa239e9527da9617686e6b.png" host=app.herokuapp.com request_id=d7e41abe-2ebd-45bd-837f-04c140203f42 fwd="186.237.160.170" dyno=web.1 connect=0ms service=2ms status=404 bytes=1902 protocol=https
2018-04-28T01:02:42.466234+00:00 heroku[router]: at=info method=GET path="/assets/application-888a5e4ac602e29fa84543f0d08fdf1f1f8821de0be9809aabb90dd2b5ac27ad.css" host=app.herokuapp.com request_id=e083a6e2-dfd7-4d75-ae15-dac0eeaa7e1e fwd="186.237.160.170" dyno=web.1 connect=0ms service=2ms status=404 bytes=1902 protocol=https

【问题讨论】:

  • 可以分享请求日志吗?
  • 您如何在视图中包含您的资产?
  • 好吧,我没有改变 rails 默认的

标签: ruby-on-rails ruby heroku


【解决方案1】:

资产需要在应用部署之前或部署时进行编译。根据我的经验,这通常是使用 Heroku buildpack 完成的。

看这里。 https://devcenter.heroku.com/articles/ruby-support#rails-4-x-applications

https://devcenter.heroku.com/articles/buildpacks

【讨论】:

    【解决方案2】:

    如果您通过 Heroku 客户端工具自己预编译它,您应该重新启动您的 dynos 以查看更改。试试heroku restart 看看是否有效

    【讨论】:

    • 懒惰的日志,谢谢你,但css仍然没有显示,如果我访问页面源上的css显示:你正在寻找的页面不存在。但js显示
    • 其实这会对 Heroku 产生相反的效果。它的filesystem is ephemeral。当测功机重新启动时,您写入文件系统的任何内容都将丢失(即使您不手动重新启动它也是一个问题——测功机是automatically restarted at least once per day)。资产需要在构建过程中编译或存储在第三方服务like Amazon S3
    • @lula 我只是觉得你的配置有问题。您能否确认运行 assets 预编译命令时是否可以在本地看到 CSS 文件?您也可以通过运行 heroku console 来签入 Heroku,然后运行 ​​Dir['public/assets/*']
    猜你喜欢
    • 1970-01-01
    • 2012-06-26
    • 2013-01-20
    • 2015-08-28
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多