2

RAILS_ENV在 rake 任务之前或之后添加有什么区别?以下是我的暂存环境中的示例:

  • RAILS_ENV在 rake 任务之后添加。

    这引发了一个错误,其原因是development默认接受环境而不是devutility环境。

    $bundle exec rake -T RAILS_ENV=devutility
    $rake aborted!
    $cannot load such file -- rack/bug
    
  • RAILS_ENV在 rake 任务之前添加

    这有效并列出了所有可用的 rake 任务。

    $RAILS_ENV=devutility bundle exec rake -T 
    rake about                          # List versions of all Rails frameworks and the environment
    rake assets:clean                   # Remove compiled assets
    rake assets:precompile              # Compile all the assets named in config.assets.precompile
    rake bourbon:install[sass_path]     # Move files to the Rails assets directory
    rake ci                             # Continuous Integration build (simplecov-rcov and deploy)
    rake cucumber                       # Alias for cucumber:ok
    rake cucumber:all                   # Run all features
    rake cucumber:ok                    # Run features that should pass
    rake cucumber:rerun                 # Record failing features and run only them if any exist
    rake cucumber:wip                   # Run features that are being worked on
    rake db:create                      # Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)
    rake db:data:dump                  ....................
    ..............
    
4

1 回答 1

2

RAILS_ENV是运行 rake 任务之前需要可用的环境变量。

当你这样做时:

RAILS_ENV=devutility bundle exec rake -T

它与以下效果相同:

export RAILS_ENV=devutility
bundle exec rake -T

RAILS_ENV看起来并不是一个论点rake,它是 Ruby 可用环境的一部分,尽管它是ENV恒定的。

于 2013-08-04T11:48:16.863 回答