What's the 'environment' task in Rake?

前端 未结 3 1236
我在风中等你
我在风中等你 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:36

    It loads in your Rails environment so you can actually use your models and what not. Otherwise, it has no idea about those things.

    So if you made a task that just did puts "HI!" then you don't need to add the :environment task to the dependencies. But if you wish to do something like User.find(1) well that will need it.

提交回复
热议问题