rake资产:预编译尝试连接到生产数据库?
问题描述:
$ rake assets:precompile
rake aborted!
could not connect to server: Network is unreachable
Is the server running on host "192.168.163.70" and accepting
TCP/IP connections on port 5432?
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/usr/local/Cellar/ruby/1.9.3-p0/bin/ruby /...]
所以我想在我的开发盒上预编译资产。出于某种原因,它试图连接到生产数据库(192.168.163.70),并且当它不能这样做时,它会中止。rake资产:预编译尝试连接到生产数据库?
它为什么这样做,我该如何解决这个问题?
答
我有以下线在我的Rake任务的一个文件
require File.expand_path(File.join(File.dirname(__FILE__), '../..', 'config', 'environment'))
删除它解决了这个问题。
答
检查您的RAILS_ENV,此时它必须设置为production
。
+0
puts Rails.env在Application.load_tasks之前给出了“development” – randomguy 2011-12-21 08:18:57
+0
'echo $ RAILS_ENV'怎么办?另外,请检查你的'database.yml',也许你在这里有错。 – 2011-12-21 08:20:51
即使在我的项目中没有rake任务,我也有同样的问题。在预编译资产时,耙子坚持连接到生产数据库。我可以通过更改database.yml来将其生产指向dev数据库来暂时解决此问题,但这样可以轻松地将指向指向错误的数据库。有更好的解决方案 – 2012-05-10 14:24:21
我想尝试调试并找到导致资产预编译加载生产配置的原因。不幸的是,我没有更好的建议。 – randomguy 2012-05-11 12:38:10