The Rails Console
November 28th, 2005
Lets face it, some of the Rails documentation can leave you a bit flustered. I mean you read the book, you read the articles you even dig through the wiki. But unfortunately some of the best stuff is just hidden away from view waiting to surprise you.
One of these little gems is the Rails console. by simply running
script/console
from your rails application directory you are dumped into an IRB session letting you run all the code of your application straight from the command line.
>> site = Site.find(1) => #Site:0x260aa80 @attributes={"id"=>"1", "short_name"=>"pensiondemo", "site_name"=>"Allen's Pension Demo"}>
Truely great. Now you may know this but do you know that.
1. You can use the TAB key to get autocompletion of all the methods on your objects in the IRB session.
2. You can dynamically reload code just type
load 'site.rb'
for instance and load your changed file.
3. Or reload it all with a quick
Dispatcher.reset_application!
4. You can pipe in a file with some Ruby code already prepared.
script/console < ruby_file.rb
The joy of IRB, learn more here. All that we wait for is the IRB enabled IDE for Rails…
1 Response to “The Rails Console”
Sorry, comments are closed for this article.
August 31st, 2006 at 05:16 PM
Dispatcher.reset_application!
Is there a shortcut. How would I make one? My console skillz are not so good.
Thank you though. Beats ctrl-D, up arrow, and retype everything.