What's the 'environment' task in Rake?

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

    Including => :environment will tell Rake to load full the application environment, giving the relevant task access to things like classes, helpers, etc. Without the :environment, you won't have access to any of those extras.

    Also => :environment itself does not make available any environment-related variables, e.g. environment, @environment, RAILS_ENV, etc.

提交回复
热议问题