Use ./script/console. It's good.
One of the cooler things about Rails has got to be ./script/console. It uses irb (tips) to load up your entire application in an interactive shell. It's a great debugging tool, and it's fun to play with your objects in real time. But even better; you can use it to get work done.
This blog uses typo, which has no admin interface (yet). Therefore, it has no easy way to create categories. For the last post, I wanted to create a new category called "Web". It doesn't get much easier than this:
# % ssh fivesevensix.com # % sites/fivesevensix.com/latest/script/console production # % irb> Category.new(:name=>"Web").save
Compare that to loading up mysql, phpmysql, or even an admin interface.
Of course I want to add that category to my article, so how about:
% irb> Article.find_by_title("Taking care of old links").categories << Category.find_by_name("Web")
(Using Rails' dynamic finders means you can easily look up the records by an arbitrary field's value. Nice.)
These are incredible tools. Anyone trying to compare the Rails environment to something in PHP, Java, etc. had better keep that in mind. For me at least, the power of it wasn't instantly apparent, but it's something I find more uses every day.
Check out this great debugging story by Tobias for more good ideas
There are 2 comments
It actually does get slightly easier than that:
Category.create(:name=>"Web")
:)
Cool stuff. Never thought of using script/console that way, now I'll use it all the time.