According to \"Custom Rake Tasks\":
desc \"Pick a random user as the winner\" task :winner => :environment do puts \"Winner: #{pick(User).name}\" end >
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.
run rake RAILS_ENV=staging db:migrate
See "Custom Rake Tasks".