脱离Rails使用ActiveRecord ( use standalone ActiveRecord without Rails)

访问量: 1086

refer to:  http://snippets.aktagon.com/snippets/257-how-to-use-activerecord-without-rails

app.rb:

require 'active_record'
require 'sqlite3'
require 'logger'

ActiveRecord::Base.logger = Logger.new('debug.log')
configuration = YAML::load(IO.read('config/database.yml'))
ActiveRecord::Base.establish_connection(configuration['development'])

class User < ActiveRecord::Base
end

database.yml:

development:
  adapter: sqlite3
  database: db/data.sqlite3
  pool: 5
  timeout: 5000

订阅/RSS Feed

Subscribe

分类/category