Ruby on Rails:heroku运行rake资源:预编译 [英] Ruby on Rails: heroku run rake assets:precompile

查看:117
本文介绍了Ruby on Rails:heroku运行rake资源:预编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮我理解 heroku运行rake资源:precompile 确实如此。自从我开始在rails上开发ruby之后,我会在推送到github和heroku之前始终运行这三个命令:

bundle exec rake assets :precompile



RAILS_ENV =生产包exec rake资产:预编译



在我推送到heroku后,我会运行:

heroku运行rake资产:预编译

code>



然而,当我在最后推送到heroku后试图运行它时,我在不同的文件上遇到了一堆相同的错误。例如:



警告。保存缓存时遇到错误...无法转储匿名类...



要查看我是否可以修复此问题, / p>

heroku运行rake assets:clean 然后 heroku运行rake资产:precompile 再次。事情是,一切工作正常,但我只是觉得如果有所有这些警告/错误。请帮助我理解。谢谢!

解决方案

预编译

为了给你更清晰的定义 - Heroku 不是唯一需要预编译资源的系统。资产预编译是大多数Rails生产环境的先决条件,因为它允许您提供静态资产(文件) - 非常适合速度和安全性。效率

以下是 Rails文档对此进行了说明:


在生产环境中,Sprockets使用上面概述的指纹识别方案
。默认情况下,Rails假定资产已经预编译为
,并且将作为静态资产由您的Web服务器提供。



在预编译阶段,MD5从内容
编译的文件,并插入文件名,因为它们是
写入光盘。这些指纹名称由Rails
帮助器用来代替清单名称。


Heroku希望您预编译您的资产是因为Heroku环境是为速度&效率;因此不希望在为应用程序的每个请求/实例编译集合时花费CPU电力。

这意味着您必须自己预编译资产,或者让 Heroku buildpacks 为你排序






Heroku

正如> CWitty ,你会想确保你在本地编译你的资产。尽管我不确定收到的错误,但我知道一件事:预编译填充 public / assets 文件夹



这意味着如果您在提交给Heroku之前在本地预先编译,那么您的所有最新资源都会存在于 public / assets 目录之前,您尝试在Heroku上运行应用程序



虽然Heroku在构建过程中执行预编译过程中,通过本地预编译,您将更安全(从异常角度看):

  $ rake资产:预编译RAILS_ENV =生产

这将使您能够填充 public / assets 文件夹,允许您在没有任何问题的情况下推送到Heroku


Please help me understand what heroku run rake assets:precompile exactly does. Ever since I began working on ruby on rails, I would always run these three commands before I push to github and heroku:

bundle exec rake assets:precompile

RAILS_ENV=production bundle exec rake assets:precompile

After I push to heroku, I would run:

heroku run rake assets:precompile

However, when I tried to run it after my last push to heroku, I got a bunch of the same errors on different files. For example:

Warning. Error encountered while saving cache ... can't dump anonymous class ...

To see if I can fix this, I ran

heroku run rake assets:clean and then heroku run rake assets:precompile again. The thing is that everything is working fine, but I just feel iffy having all these warnings/errors. Please help me understand. Thank you!

解决方案

Precompile

To give you some clearer definitions - Heroku isn't the only system which requires you to "precompile" your assets. Asset precompilation is a pre-requisite of most Rails production environments, as it allows you to serve static assets (files) - perfect for speed & efficiency

Here's what the Rails documentation says about it:

In the production environment Sprockets uses the fingerprinting scheme outlined above. By default Rails assumes assets have been precompiled and will be served as static assets by your web server.

During the precompilation phase an MD5 is generated from the contents of the compiled files, and inserted into the filenames as they are written to disc. These fingerprinted names are used by the Rails helpers in place of the manifest name.

The reason why Heroku wants you to precompile your assets is because the Heroku environment is designed for speed & efficiency; and hence does not want to expend CPU power on compiling the assests for each request / instanace of your app

This means you have to either precompile the assets yourself, or let the Heroku buildpacks sort that out for you


Heroku

As mentioned by CWitty, you'll want to make sure you compile your assets locally. And whilst I'm not sure about the errors you've received, I do know one thing: precompilation populates the public/assets folder

This means if you precompile locally before submitting to Heroku, you'll have all your latest assets present in your public/assets directory before you try and run the application on Heroku

Although Heroku does perform precompilation as part of the build process, you'll be much safer (from an exception perspective) by precompiling locally:

$ rake assets:precompile RAILS_ENV=production

This will give you the ability to populate the public/assets folder, allowing you to then push to Heroku without any issues

这篇关于Ruby on Rails:heroku运行rake资源:预编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆