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
相关文章推荐
- How to use ActiveRecord without Rails
- [quote]HowTo Format Date For Display or Use In a Shell Script
- how to change the original ruby version in Rails app
- How to use Regular Expression in LotusScript
- How to install Ruby on rails in Windows 2003/xp 如何安装ROR
- How to fix the “msvcrt-ruby18.dll is missing from your computer” error message in Ruby on Rails
- How to install Ruby on Rails in Ubuntu 11.10
- How to use an ActiveX script task to create a loop in DTS
- how to test observe with rspec in ruby on rails.
- how to test observe with rspec in ruby on rails.
- How to Use Memcached With Ruby on Rails on Ubuntu 12.04 LTS
- How to use ftp in a shell script
- How to format date for display or to use in a shell script
- How to Generate PDF in Ruby on Rails(HowtoGeneratePDFs) ZT
- How To Use MySQL with Your Ruby on Rails Application on Ubuntu 14.04
- How to define a bash function for use in any script?
- how to configure and use activemq in camel
- How to use ValidationSummary control in asp.net
- How to use freely resizable font in in Java ME
- How To Call Run() Method of the Microsoft Script Control in C++