Skip to content

Instantly share code, notes, and snippets.

@r3nya
Created March 31, 2013 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r3nya/5281080 to your computer and use it in GitHub Desktop.
Save r3nya/5281080 to your computer and use it in GitHub Desktop.
require 'awesome_print'
require 'active_record'
require 'pg'
require 'pp'
require 'roo'
ActiveRecord::Base.establish_connection(
:adapter => 'postgresql',
:host => 'localhost',
:username => 'kevin',
:database => 'tinkov_dev',
:password => '123'
)
class Schema < ActiveRecord::Migration
def change
create_table :merchants do |t|
t.string :name
end
add_index :merchants, :name
end
end
Schema.new.change
# Mdel
class Merchant < ActiveRecord::Base
attr_accessible :name
end
# Get data from spreadsheet
merchants = Roo::Spreadsheet.open('/Users/kevin/Documents/tin_olimp/merchants.xlsx').to_a
# Add to table
Merchant.transaction do
merchants.flatten.each { |merchant| Merchant.create!(:name => merchant)}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment