Home 脱离rails使用activerecord Usestandaloneactiverecordwithoutrails
Post
Cancel

脱离rails使用activerecord Usestandaloneactiverecordwithoutrails

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
This post is licensed under CC BY 4.0 by the author.