populator.rake

Ruby code posted by Railscasts
created at 28 Dec 21:47, updated at 29 Dec 04:28

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
namespace :db do
  desc "Erase and fill database"
  task :populate => :environment do
    [Product].each(&:delete_all)
    

      Product.populate 10..100 do |product|
        product.title = Populator.words(1..5).titleize
        product.description = Populator.sentences(2..10)
        product.price = [4.99, 19.95, 100]
      end
  end
end
355 Bytes in 2 ms with coderay