如何在Heroku上预编译资源时普遍跳过数据库触摸 [英] How to universally skip database touches when precompiling assets on Heroku

查看:186
本文介绍了如何在Heroku上预编译资源时普遍跳过数据库触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个Rails 3.1应用程序部署到Heroku的Cedar堆栈。使用 Heroku Cedar和Rails 3.1 ,您可以在本地编译资源,让Heroku在您推送时编译它们(在编译),或者让它们在应用程序运行时及时编译。

I'm deploying a Rails 3.1 app to Heroku's Cedar stack. With Heroku Cedar and Rails 3.1, you can compile the assets yourself locally, let Heroku compile them when you push (during "slug compilation"), or have them be compiled just-in-time while the app is running. I want to do the middle option, letting Heroku precompile the assets.

当Heroku运行assets:precompile任务时,会出现无法连接到服务器,因为应用程序正在尝试连接到数据库,但在该阶段的slug编译没有可用的数据库。缺少数据库连接是预期和不可避免的在这一点上。我正在寻找一种方法来移动它,因为数据库连接对资产预编译并不重要。

When Heroku runs the assets:precompile task, it errors with "could not connect to server" because the app is trying to connect to the database but no database is available at that stage of slug compilation. The lack of database connection is expected and unavoidable at this point. I'm looking for a way to move past it, because a database connection isn't crucial to asset precompilation.

我的应用程序试图连接到数据库是Devise。在routes.rb中有一个 devise_for:users 行,想要查看User模型。

The part of my app that's trying to connect to the database is Devise. There's a devise_for :users line in routes.rb that wants to look at the User model.

写一个耙子任务,存根devise_for并使其成为资产prereq:precompile。我认为这将解决我的问题,但我正在寻找一个更通用的解决方案,我可以使用在任何 Rails 3.1应用程序与Heroku上的这个问题。

I could just write a rake task that stubs out devise_for and make it a prereq of assets:precompile. I think that would solve my problem, but I'm looking for a more universal solution that I could use on any Rails 3.1 app with this problem on Heroku.

有没有什么,或者你可以设想任何沉默数据库连接错误,同时仍然运行应用程序足够有路由和资产路径生成?

Is there anything out there, or can you conceive of anything that silences database connection errors while still running the app enough to have route and asset path generation?

显然,如果应用程序需要在启动期间读/写数据,我们不能存根,但是我们可以自动伪造每个ActiveRecord模型吗?

Obviously if an app needs to read/write data during startup, we can't stub that, but can we fake every ActiveRecord model automatically?

推荐答案

编辑:此答案已过期,不再有效 - 见fringd的回答。

This answer is out of date and no longer works - See fringd's answer.

devise现在添加了一个检查来解决这个特殊的问题。请参阅问题 fix 在Github上。通过提供RAILS_ASSETS_PRECOMPILE环境,配置设备应该跳过构建路由

Not quite a universal stubbing but devise has added a check now to fix this particular problem . See the issue and fix on Github. By providing a RAILS_ASSETS_PRECOMPILE environment config devise should skip building the routes

这篇关于如何在Heroku上预编译资源时普遍跳过数据库触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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