Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -- Export
- require 'csv'
- CSV.open('books.csv', 'w') do |file|
- Book.all.each {|b|
- file << [
- b.isbn, b.sku_number, b.title,
- b.author_family, b.author_given, b.author, '',
- b.edition, b.description, b.sale_price,
- b.cover.try(:full_filename),
- b.category, b.featured_content
- ]
- }
- end
- # -- Import
- require 'csv'
- CSV.open('/var/apps/catawba/current/books.csv', 'r') do |b|
- begin
- book = Book.new({
- :isbn => b[0],
- :sku => b[1],
- :title => b[2],
- :author_given => b[3],
- :author_family => b[4],
- :author_fn => b[5],
- :author_email => b[6],
- :edition => b[7],
- :description => b[8],
- :price => b[9]
- })
- begin
- book.cover = File.open(b[10])
- rescue Exception => e
- puts = e
- end
- book.save!
- book.categories << Category.find_by_name(b[11])
- book.categories << Category.find_by_name("Featured Books") if b[12] =~ /true/
- rescue Exception => e
- puts b[0] +" - "+ e
- end
- end
Add Comment
Please, Sign In to add comment