Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Using ActiveRecord outside of a Rails app
require 'active_record'
require 'mysql2'
# Database Connection
adapter: 'mysql2', # or 'postgresql' or 'sqlite3'
host: 'localhost',
database: 'chc_user_auth_direct_login',
username: 'root',
password: ''
# Database Class
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :role_ids, :as => :admin
attr_accessible :name, :email, :password, :password_confirmation, :remember_me
# Now do stuff with it
puts SomeClass.find :all
some_class =
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment