Created
October 17, 2012 14:43
-
-
Save yao2030/3905894 to your computer and use it in GitHub Desktop.
using ActiveRecord outside rails
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 'rubygems' | |
require 'active_record' | |
require 'mysql2' | |
require 'yaml' | |
dbconfig = YAML::load(File.open('database.yml')) | |
ActiveRecord::Base.establish_connection(dbconfig) | |
class Duck < ActiveRecord::Base | |
end | |
puts Duck.count |
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
adapter: mysql | |
database: dbfile | |
username: username | |
password: 123 | |
host: localhost |
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
gem install mysql2 | |
add require 'mysql2' to ar_example.rb | |
create a table 'ducks' in database 'dbfile' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment