How to use ActiveRecord in a ruby script outside Rails?

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

你可能感兴趣的:(How to use ActiveRecord in a ruby script outside Rails?)