Created
March 31, 2013 15:54
-
-
Save r3nya/5281080 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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