简体   繁体   English

使用Rails 3.1预编译资产

[英]Precompiling Assets with Rails 3.1

I'm pushing changes to Heroku and I get ... 我向Heroku推送更改,我得到了...

rake aborted! 耙子流产了!
could not connect to server: Connection refused 无法连接到服务器:连接被拒绝
Is the server running on host "127.0.0.1" and accepting 服务器是否在主机“ 127.0.0.1”上运行并接受
TCP/IP connections on port 5432? 端口5432上的TCP / IP连接?

When I consult the Heroku documentation Here , it tells me I need to "configure a nonexistent database in your local config/database.yml" I'm not sure how to create a "nonexistent database"? 当我查阅Heroku文档Here时 ,它告诉我需要“在本地config / database.yml中配置不存在的数据库”我不确定如何创建“不存在的数据库”吗? I'm a beginner and would appreciate any help you can give me. 我是一个初学者,希望您能给我任何帮助。 Thanks. 谢谢。

On Heroku, you must set this line in your config/application.rb: 在Heroku上,您必须在config / application.rb中设置以下行:

config.assets.initialize_on_precompile = false

http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets

For faster asset precompiles, you can partially load your application by setting config.assets.initialize_on_precompile to false in config/application.rb, though in that case templates cannot see application objects or methods. 为了更快地进行资产预编译,您可以通过在config / application.rb中将config.assets.initialize_on_precompile设置为false来部分加载应用程序,尽管在这种情况下,模板看不到应用程序对象或方法。 Heroku requires this to be false. Heroku要求此为假。

It means put in the name of a database that doesn't actually exist in your local dev environment. 这意味着输入本地开发环境中实际上不存在的数据库的名称。 Then try and run rake assets:precompile 然后尝试运行rake assets:precompile

You're simulating the same scenario locally (an unavailable db). 您正在本地模拟相同的场景(一个不可用的数据库)。

Are you using Devise in this app? 您是否在此应用程序中使用Devise? It had a known issue similar to this . 它有一个与此类似的已知问题 You may want to update that gem. 您可能要更新该gem。

I ran into the same problem. 我遇到了同样的问题。 It seems that for some reason the DATABASE_URL environment variable is not set at the time of asset precompilation. 似乎由于某种原因,在资产预编译时未设置DATABASE_URL环境变量。 A workaround is to set the DATABASE_URL in the production.rb file. 解决方法是在production.rb文件中设置DATABASE_URL。 ENV["DATABASE_URL"] = <your db url> That should fix the problem. ENV["DATABASE_URL"] = <your db url>应该可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM