The Rails Console Makes Test Object Creation and Debugging Easy

by barce on August 21, 2008

I really like how the Rails console solves the problems of test object creation and debugging.

Usually, a web developer will push code to the webserver and hit shift-reload on the web browser. With the Rails console, you can avoid all that shift-reload madness.

If I wanted to create 10000 blog posts for testing, I could do something like this:

script/console
10000.times
{ |i| Post.create(:title => “post number: ” + i.to_s, :body => “autogen Booyah!”) }

Through the console I can also do debugging pretty easily:

>> p = Post.find 888

And get this as output:

=> #

A lot of problems in Rails are just solved by running script/console and checking the values of certain variables that are pretty hard to get at through a web browser.

There is pretty much no limit to what can be done through the Rails console. Konstantin Gredeskoul, web developer and songwriter, has found a way to load session data through the console.

Leave a Comment

Previous post:

Next post: