Sha256: 2a150c94a04fcb38c60e68c38e11caf600a43d8a94c8c3fde0745d27e7f7eb40

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 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/products/"
    source = "#{RAILS_ROOT}/lib/tasks/sample/images/"
    FileUtils.mkdir_p target
    #File.makedirs target
    
    Dir.new(source).each do |filename|
      if not (filename == '.' or filename == '..' or filename == '.svn')
        src = source + "#{filename}"
        dst = target + "#{filename}"
        FileUtils.cp 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

3 entries across 3 versions & 1 rubygems

Version Path
railscart-0.0.1 starter-app/lib/tasks/rc_sample_data.rake
railscart-0.0.2 starter_app/lib/tasks/rc_sample_data.rake
railscart-0.0.3 starter_app/lib/tasks/rc_sample_data.rake