Hivelogic has an excellent writeup to get you all setup and riding the Rails.
A Do-It-Yourself Guide to Installing Ruby, Rails, and FastCGI
Have fun!
The Life of an Internet Bedouin
April 4th, 2005 — Ruby
Hivelogic has an excellent writeup to get you all setup and riding the Rails.
A Do-It-Yourself Guide to Installing Ruby, Rails, and FastCGI
Have fun!
April 4th, 2005 — Ruby
I’m building a Rails web application and am having a great time.
I came across the need to run some Ruby scripts from the command line. While I could have used Ruby/mysql to perform the tasks, I really wanted Active Record access (for obvious reasons).
Here is how you do it:
require 'rubygems'
require_gem 'activerecord'
require '/path/to/your/app/models/category'
require '/path/to/your/app/models/item'
puts 'AR test begin.'
#Connect to the database
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:username => "youruser",
:password => "yourpwd",
:database => "yourdb"
)
#turn on AR logging
ActiveRecord::Base.logger = Logger.new('ar_log.txt')
puts 'Finding all categories...'
p Category.find_all
puts 'AR test done.'
The results of a test run:
AR test begin.
Finding all categories...
[#
The Active Record log file:
# Logfile created on Mon Apr 04 11:21:03 PDT 2005 by logger.rb/1.5.2.4
Category Columns (0.000509) SHOW FIELDS FROM items
Category Load (0.068370) SELECT * FROM items WHERE (type = 'Category' )
That’s all there is to it!