Sha256: 3e9455fd1126a1f27db1ae5339e3dbea3e8a9be160fbe0b059a8cc3823fa6297

Contents?: true

Size: 644 Bytes

Versions: 19

Compression:

Stored size: 644 Bytes

Contents

#!/usr/bin/env ruby -rubygems

require File.join(File.dirname(__FILE__), 'authentication')

require "csv" # faster_csv (ruby 1.9)

lines = CSV.read(File.join(File.dirname(__FILE__), 'guidebooks.csv')) # Exported an Excel file as CSV

lines.slice!(0) # remove header line

collection = StorageRoom::Collection.find('4dda7761b65245fde100005d')
Guidebook = collection.entry_class

lines.each do |row|
  guidebook = Guidebook.new(:title => row[0], :price => row[1].to_f)

  if guidebook.save
    puts "Guidebook saved: #{guidebook.title}, #{guidebook.price}"
  else
    puts "Guidebook could not be saved: #{guidebook.errors.join(', ')}"
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
storage_room-0.3.24 examples/import_csv.rb
storage_room-0.3.23 examples/import_csv.rb
storage_room-0.3.22 examples/import_csv.rb
storage_room-0.3.21 examples/import_csv.rb
storage_room-0.3.20 examples/import_csv.rb
storage_room-0.3.19 examples/import_csv.rb
storage_room-0.3.18 examples/import_csv.rb
storage_room-0.3.17 examples/import_csv.rb
storage_room-0.3.16 examples/import_csv.rb
storage_room-0.3.15 examples/import_csv.rb
storage_room-0.3.14 examples/import_csv.rb
storage_room-0.3.13 examples/import_csv.rb
storage_room-0.3.12 examples/import_csv.rb
storage_room-0.3.11 examples/import_csv.rb
storage_room-0.3.10 examples/import_csv.rb
storage_room-0.3.9 examples/import_csv.rb
storage_room-0.3.8 examples/import_csv.rb
storage_room-0.3.7 examples/import_csv.rb
storage_room-0.3.6 examples/import_csv.rb