我在一个新的“演示”应用程序( )中添加puts "--- #{__FILE__}"
了以下每个文件的顶部:rails new demo
config.ru
config/application.rb
config/boot.rb
config/environment.rb
config/environments/development.rb
config/initializers/hello.rb
然后我简单地用 启动应用程序rails server
,并得到以下输出(....
为了简洁起见):
--- /Volumes/..../initialization-order/demo/config/boot.rb
--- /Volumes/..../initialization-order/demo/config/application.rb
=> Booting WEBrick
=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
--- /Volumes/..../initialization-order/demo/config.ru
--- /Volumes/..../initialization-order/demo/config/environment.rb
--- /Volumes/..../initialization-order/demo/config/environments/development.rb
--- /Volumes/..../initialization-order/demo/config/initializers/hello.rb
[2013-05-16 15:05:59] INFO WEBrick 1.3.1
[2013-05-16 15:05:59] INFO ruby 1.9.3 (2013-02-22) [x86_64-darwin12.3.0]
[2013-05-16 15:05:59] INFO WEBrick::HTTPServer#start: pid=91029 port=3000
^C[2013-05-16 15:06:25] INFO going to shutdown ...
[2013-05-16 15:06:25] INFO WEBrick::HTTPServer#start done.
Exiting
因此初始化顺序如下:
/config/boot.rb
/config/application.rb
/config.ru
/config/environment.rb
/config/environments/development.rb
/config/initializers/hello.rb
因此,如果您希望在之前config/environments/*.rb
(和之前/config/initializers/*.rb
)加载您的环境变量,那么请阅读接下来的内容。