Sha256: 4bb6f00cb294463767abfbe82aabdeb92563cf2bffa9adcd48f531e823765d81
Contents?: true
Size: 1.1 KB
Versions: 2
Compression:
Stored size: 1.1 KB
Contents
namespace :db do namespace :sample do desc "creates sample blog posts" task :blog do require 'faker' require Rails.root.join('config/environment.rb') image_dir = File.expand_path("../sample", __FILE__) images = Dir[image_dir + "/*.jpg"] product_ids = Product.select('id').all.collect(&:id) rescue [] 25.times { |i| post = Post.create( :title => Faker::Lorem.sentence, :posted_at => Time.now - i * rand(10000000), :body => Faker::Lorem.paragraph, :tag_list => Faker::Lorem.words(rand(10)).join(", ") ) rand(5).times { |i| image = post.images.create(:attachment => File.open(images.sort_by{rand}.first), :alt => Faker::Lorem.sentence) } unless product_ids.empty? rand(5).times { |i| post.post_products.create(:product => Product.find(product_ids.sort_by{rand}.first), :position => i) } end print "*" } puts "\ndone." end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
spree_essential_blog-0.1.0 | lib/tasks/sample.rake |
spree_essential_blog-0.1.0.rc1 | lib/tasks/sample.rake |