Skip to content

Instantly share code, notes, and snippets.

@bruno-
Last active August 29, 2015 14:06
Show Gist options
  • Save bruno-/babba3279f8d03be423e to your computer and use it in GitHub Desktop.
Save bruno-/babba3279f8d03be423e to your computer and use it in GitHub Desktop.
Using standalone ActiveRecord is really easy
require "active_record"
require "pg"
# AR connection
ActiveRecord::Base.establish_connection(
adapter: "postgresql",
database: "lynda_test",
username: "<db_username>",
password: "<db_password>",
host: "localhost",
port: "5432",
)
# models (tables have to exist in the DB)
class Customer < ActiveRecord::Base
has_many :sales
end
class Item < ActiveRecord::Base
has_many :sales
end
class Sale < ActiveRecord::Base
belongs_to :customer
belongs_to :item
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment