您的位置:首页 > 编程语言 > Ruby

How to use ActiveRecord in a ruby script outside Rails?

2012-02-07 17:32 597 查看
require "rubygems"
require "activerecord"
# Use the following line instead (without the comment hash) if you are using JRuby
#require "active_record"

#Change this to reflect your database settings
ActiveRecord::Base.establish_connection (
:adapter => "mysql",
:host => "localhost",
:username => "root",
:password => "password",
:database => "some_database")

#Now define your classes from the database as always
class SomeClass < ActiveRecord::Base
#blah, blah, blah
end

#Now do stuff with it
some_class = SomeClass.new
some_other_stuff = SomeClass.find :all
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: