Ruby on rails 在rake任务之前或之后添加RAILS_ENV之间的区别
在rake任务之前或之后添加Ruby on rails 在rake任务之前或之后添加RAILS_ENV之间的区别,ruby-on-rails,ruby,rake,environment-variables,ruby-on-rails-4,Ruby On Rails,Ruby,Rake,Environment Variables,Ruby On Rails 4,在rake任务之前或之后添加RAILS\u ENV有什么区别?以下是我的登台环境中的示例: 在rake任务之后添加RAILS\u ENV 这引发了一个错误,其原因是默认接受开发环境,而不是将开发作为环境 $bundle exec rake -T RAILS_ENV=devutility $rake aborted! $cannot load such file -- rack/bug 在rake任务之前添加RAILS\u ENV 这将起作用并列出所有可用的rake任务 $RAILS_ENV
RAILS\u ENV
有什么区别?以下是我的登台环境中的示例:
- 在rake任务之后添加
这引发了一个错误,其原因是默认接受RAILS\u ENV
环境,而不是将开发
作为环境开发
$bundle exec rake -T RAILS_ENV=devutility $rake aborted! $cannot load such file -- rack/bug
- 在rake任务之前添加
这将起作用并列出所有可用的rake任务RAILS\u ENV
$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 .................... ..............
RAILS\u ENV
是一个环境变量,在运行rake任务之前必须可用
当您这样做时:
RAILS_ENV=devutility bundle exec rake -T
其影响与:
export RAILS_ENV=devutility
bundle exec rake -T
RAILS\u ENV
似乎不是rake
的参数,它是Ruby可用环境的一部分,尽管它是ENV
常量。好的,但是你知道为什么它在rake任务结束时会表现出奇怪的行为吗?是的,因为您运行了rake任务,然后设置了RAILS_ENV,所以在运行rake时没有设置它。@AnkitG这对您有帮助吗?