Created
March 27, 2014 15:11
-
-
Save kany/9809730 to your computer and use it in GitHub Desktop.
Using ActiveRecord outside of a Rails app
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 'active_record' | |
require 'mysql2' | |
# Database Connection | |
ActiveRecord::Base.establish_connection( | |
adapter: 'mysql2', # or 'postgresql' or 'sqlite3' | |
host: 'localhost', | |
database: 'chc_user_auth_direct_login', | |
username: 'root', | |
password: '' | |
) | |
# Database Class | |
class User < ActiveRecord::Base | |
rolify | |
# 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 | |
end | |
# Now do stuff with it | |
puts SomeClass.find :all | |
some_class = SomeClass.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment