rails common sense

/tasks/xx.rake

custom task

 

rake --tasks

rake -vT

http://railscasts.com/episodes/66-custom-rake-tasks

namespace :hbase do

  desc "Pick a random user as the winner"

  task :test => :environment do

    puts "Winner"

  end

 

  desc "Pick a random product as the prize"

  task :prize => :environment do

    puts "Prize: #{pick(Product).name}"

  end

 

  desc "Pick a random prize and winner"

  task :all => [:prize, :winner]

 

  def pick(model_class)

    model_class.find(:first, :order => 'RAND()')

  end

end

你可能感兴趣的:(Rails)