Sha256: 959fd4e26506f6931526f1cd5ea08e08ad94c851f5ed334555a7402b4c0b5e8d

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

namespace :rc do
  desc "Populates store with sample products"
  task :sample_data => :environment do
    require 'active_record/fixtures'
    require 'custom_fixtures'

    # load initial database fixtures (in db/sample/*.yml) into the current environment's database
    ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
    Dir.glob(File.join(RAILS_ROOT, 'db', 'sample', '*.{yml,csv}')).each do |fixture_file|
      Fixtures.create_fixtures('db/sample', File.basename(fixture_file, '.*'))
    end
    
    # make product images available to the app
    target = "#{RAILS_ROOT}/public/images/"
    source = "#{RAILS_ROOT}/lib/tasks/sample/products/"
    #FileUtils.mkdir_p target
    #File.makedirs target
    
    FileUtils.cp_r source, target
    
    #Dir.new(source).each do |filename|
    #  if not (filename == '.' or filename == '..' or filename == '.svn')
    #    src = source + "#{filename}"
    #    dst = target + "#{filename}"
    #    FileUtils.cp_r src, dst
    #  end
      #copy filename, target, true
      #puts "Inside /usr/bin is something called #{filename}"
    #end
    puts "Sample products have been loaded into to the store"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
railscart-0.0.4 starter_app/lib/tasks/rc_sample_data.rake