根据环境配置Unicorn.rb

6

在config/unicorn.rb中有一行代码如下:

working_directory "/SomePath/Web\ Development/Rails/learning"

然而在生产环境中,需要使用另一个路径。我希望尽可能多地将其纳入源代码控制(目前还没有放弃什么)。有没有一种根据环境设置 working_directory 的方法?

3个回答

4

您正在尝试访问RAILS_ENV或RACK_ENV吗?应该通过“ENV”来访问...

ENV['RAILS_ENV'] 

... or ...

ENV['RACK_ENV']

当您向独角兽传递“-E”标志时,应该提供其中一个(我无法确定哪个,但我认为是RACK_ENV)。

1
是的,RACK_ENV 可用。据我所知,RAILS_ENV 不可用。 - Jonathan del Strother

3
使用unicorn_rails会使环境变量可用。

+1 - 这对我很有用,解决了我的日志问题,其中我的unicorn.rb正在查看ENV ['RAILS_ENV']。 - Joe

0

你可以通过RAILS_ENV访问Rails环境。


我认为此时它尚未初始化,似乎无法在config/unicorn.rb中使用它。 - Matthew
你是否设置了-E标志来为独角兽设置RAILS_ENV/RACK_ENV?请参见:https://github.com/defunkt/unicorn/blob/master/Documentation/unicorn_rails.1.txt - Vodun
1
如果我运行 unicorn -c config/unicorn.rb -E "development",那么当我尝试访问 RAILS_ENV 或者 RACK_ENV 时,我仍然会遇到一个未初始化的常量错误。 - Matthew
使用 unicorn_rails -c config/unicorn.rb -E "development" 命令启动应用程序?在最坏的情况下,您可以通过 RAILS_ENV="development" unicorn_rails 命令强制指定环境。 - Vodun

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接