Skip to content

Instantly share code, notes, and snippets.

@stungeye
Created January 27, 2015 16:45
Show Gist options
  • Save stungeye/80ff91b90b8e4a1b4c56 to your computer and use it in GitHub Desktop.
Save stungeye/80ff91b90b8e4a1b4c56 to your computer and use it in GitHub Desktop.
Simple AR without Rails Example
require 'active_record'
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => 'db/development.sqlite3'
class Customer < ActiveRecord::Base
# Associated with the customers.
end
# SELECT * FROM customers ORDER BY id ASC LIMIT 1
first_customer = Customer.first
puts "#{first_customer.name} lives in the city of #{first_customer.city}."
# SELECT COUNT(*) FROM customers
customer_count = Customer.count
puts "My customers table contains #{customer_count} customers."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment