I was wondering if ActiveRecord support was available for database
access without requiring Ruby on Rails? Just for regular Ruby scripts?
Unless your database schema is too far off the Rails path (such as
using composite primary keys), Active Record works very well on
standard alone scripts. The great thing is that Active Record will
just mirror your database structure into the objects, so just by
defining:
class Product < ActiveRecord::Base
end
You'll have an interface to the products database with all the fields
available as properly type-casted attributes, so you can do
Product.find(1).name without first defining that Product does indeed
have a name, as stated in the database already by the field "name".
And of course, it'll work for creating too:
Product.create :name =3D> "Delicious Cakes", :description =3D> "They're yum=
my!"
Again, you need neither explicitly declare name nor description for
this to work.
--=20
David Heinemeier Hansson
http://www.loudthinking.com -- Broadcasting Brain
http://www.basecamphq.com -- Online project management
http://www.backpackit.com -- Personal information manager
http://www.rubyonrails.com -- Web-application framework