Quick Way To Experiment With ActiveRecord
A while back I spent a fair amount of time with the Pro Active Record book, learning all about dynamic finders, associations, validations, and all the other magic it has, sometimes it was a bit of a pain to set everything up by hand, typing out the .rb model files, creating the databases, etc. I figured, why do all that work (yea yea, I know it’s just typing out some text) when you have the power of rails, generators and rake at your disposal. So what I’d do is simply use the rails generators.
$ rails test && cd test [...] $ script/generate model User name:string age:integer [...] $ rake db:create && rake db:migrate $ vi app/models/user.rb # optional $ script/console
Voila! Four commands and you’re in an interactive shell that will let you manipulate your models, add data, run finds, etc. No need to deal with anything other than an already set up database and model file, and you have a nice interactive shell to boot.
Best part? Just do an “rm -rf <directory>” when you’re done to nuke the directory and either start again or try out the next experiment.