Rails 3.1.1资产管道Heroku缓存陷阱 [英] Rails 3.1.1 asset pipeline Heroku caching gotcha

查看:119
本文介绍了Rails 3.1.1资产管道Heroku缓存陷阱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简而言之,问题在于,在开发模式下,我们会对CSS或JS文件进行更改,但始终会获取这些文件的缓存/旧版本。我做的没有任何影响。我检查了几十次配置,尝试了每个配置值的组合,但始终保持相同的结果:过时/缓存的文件。我必须真正在生产模式下运行,并在每次更改测试后重新启动服务器。



我花了几天的时间在这个问题上嘲笑我的头发,看了几十个计算器问题在资产管道上,但从来没有找到一个解决它,所以我想我会张贴在这里为后人。

我们使用Heroku并预编译我们的资产,因为Heroku无法预编译对我们来说(我们也使用devise,这显然是heroku预编译失败的原因)。因此,为了将我们预编译的资源提升到Heroku,我们必须将它们检入到git中。



这是问题



当我们升级到 Rails 3.1.1 资产预编译产生的文件中名称中带有和不带有MD5散列。我没有想太多,然后继续检查所有这些文件,以便推送到heroku。有一段时间后,我注意到在开发模式下缓存结果的问题。没有MD5散列的预编译和签入资产被作为静态文件提供给/ public / assets,阻止我们看到我们在/ app / assets中做出的任何更改。



<在终于意识到这一点之后,我运行了git rm / public / assets并且一切都重新运行。所以结论是:小心检查资产到git!



要将这个问题变成一个问题:其他人如何做到这一点?我错过了明显的东西吗?我真的很喜欢Heroku为我预编译我的资产,但是由于设计原因我收集的db连接错误失败了。我曾希望Rails 3.1.1解决了这个问题,但它没有解决这个问题。

你有没有检查过这个在github上讨论问题?具体来说,何塞·瓦林姆说:

lockquote
Rails 3.1.1 final有一个名为
config.assets.initialize_on_precompile的方法。如果您将其设置为false,那么您的
应该是好的,但它不会允许您访问您的资产(您可能不应该)的
的模型信息。


也许这会让预编译在Heroku上发生。


The problem in a nutshell is that in development mode we'd make changes to CSS or JS files but would always get cached/old versions of these files. Nothing I did had any effect. I checked configuration dozens of times and tried every combination of config values but always kept getting the same results: stale/cached files. I had to actually run in production mode and restart the server after every change to test.

I spent days tearing my hair out over this issue, looked at dozens of stackoverflow questions on the asset pipeline but never found one that addressed it so I thought I'd post it here for posterity.

We use Heroku and precompile our assets because Heroku fails to precompile for us (we also use devise which apparently is the cause of the heroku precompilation failure). So in order to push our precompiled assets up to Heroku we have to check them in to git.

Here's the problem.

When we upgraded to Rails 3.1.1 asset precompilation produced files both with and without the MD5 hash in the name. I didn't think much of this and went ahead and checked all these files in so I could push to heroku. Sometime later I noticed the problem with cached results in development mode. The precompiled and checked in assets without the MD5 hashes were being served from /public/assets as static files which prevented us from seeing any changes we were making in /app/assets.

After finally realizing this I ran git rm /public/assets and everything works again. So the takeaway is: Be careful checking assets into git!

To turn this into a question: how do others do this? Am I missing something obvious? What I'd really like is for Heroku to precompile my assets for me but it is failing with a db connection error that I gather is because of devise. I had hoped Rails 3.1.1 fixed this but it didn't.

解决方案

Have you checked out this devise issue on github? Specifically Jose Valim says

Rails 3.1.1 final has a method called config.assets.initialize_on_precompile. If you set it to false, you should be good but it won't allow you to access model information on your assets (which you probably shouldn't anyway).

Maybe this will allow the precompile to happen on Heroku for you.

这篇关于Rails 3.1.1资产管道Heroku缓存陷阱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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