What's the 'environment' task in Rake?

前端 未结 3 1225
我在风中等你
我在风中等你 2020-12-04 13:40

According to \"Custom Rake Tasks\":

desc \"Pick a random user as the winner\"
task :winner => :environment do
  puts \"Winner: #{pick(User).name}\"
end
         


        
3条回答
  •  爱一瞬间的悲伤
    2020-12-04 14:18

    You can get access to your models, and in fact, your whole environment by making tasks dependent on the environment task. This lets you do things like run rake RAILS_ENV=staging db:migrate.

    See "Custom Rake Tasks".

提交回复
热议问题