在rake任务之前或之后添加RAILS_ENV
有什么区别以下是我的登台环境中的示例:
在rake任务之后添加RAILS_ENV
。
这引发了一个错误,其原因是默认接受development
环境,而不接受devutility
环境。
$bundle exec rake -T RAILS_ENV=devutility
$rake aborted!
$cannot load such file -- rack/bug
在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 ....................
..............
最佳答案
RAILS_ENV
是一个环境变量,在运行rake任务之前需要使用它。
当你这样做时:
RAILS_ENV=devutility bundle exec rake -T
其影响与:
export RAILS_ENV=devutility
bundle exec rake -T
RAILS_ENV
不是rake
的参数,因为它看起来像是Ruby可用环境的一部分,尽管它是ENV
常量。关于ruby-on-rails - 在rake任务之前或之后添加RAILS_ENV之间的区别,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18041925/