When programming javascript Firebug has a console that lets you type in javascript and fire it against an open window. The Tandy TRS-80 command line let me type in basic programs on the fly. I also have faint recollections of having a command window that came in handy with other languages. However, none of these ever proved incredibly useful for me, or left any strong imprint on my impressionable mind.
That is, until I started working with RoR and was introduced to the script/console. Hello “script/console”, nice to meet you
At first it seemed mildly useful, but the other day after a minor hiccup it proved itself extremely helpful.
The biggest thing to make sure and not overlook is the ability to execute commands like this:
>>user_list = User.find(:all)
>>user_list.each{ |u| u.update_attributes(:is_crazy, true) if u.has_duplicate_phone_numbers? }
I’ve done a lot of work with databases, but I am by no means a SQL guru. These 2 lines of code took me under a minute to write and there aren’t enough users in our system to have to worry about the execution time. The hiccup we had the other day involved sending out our monthly product mailer. We managed to have 2 servers that were asked to create mailer messages, so everyone started getting 2 of our product mailers! Eek!
Not the end of the world, but not so fun. We shut down the mailer. 1/3 of the mail did not get sent at all, a handful of people only got one mail, and the rest received 2 mails. So, I needed to enable only 1 mailer for the 1/3 of the people who hadn’t received any mails, and turn the rest of the records to a failed status. Thank you script/console. Literally under 2 minutes I was able to do some command line work and bring the mailer back up. I’m slowly moving myself away from directly doing sql, and loving every inch away I get.
You can see our admin interface – the fails are the duplicate mailers that I automatically failed:
