As much as we would all like to be mystical future seeing yogis, no one is perfect especially when it comes to naming your models and variables in a new project. Recently i decided to switch a horribly named model “info” to a more descriptive “whymail” for my project at Why Spam. After dreading the first attempted model renaming, i made a backup of my project and did a Ctrl+Shift+F with textmate, un-selected ignore case did a find and replace of “Info” to “Whymail” and another one of “info” to “whymail” this way i’ll make sure to keep the proper case depending on how we’re calling it, this also will automatically take care of plural cases such as info(s) to whymail(s).

textmate find and replace
After this painless two step process, i had to rename, my model, controller, view folder, and specs. After a bit of trial and error i realized that I had accidentally done the find and replace on all of my plugins as well, thats why i keep a backup!! I just copied my previous plugin folder to the current plugin folder to fix that problem, then I migrated my databases and I was good to go. Not painful at all.
While I got lucky, the biggest caveat you may run into is words nested in other words. So renaming a model from “aft” to “bow” may also accidentally change your “draft” model to “drbow”, so be careful and make sure you test your code well before and after the change. You can also do a find and replace with regex with textmate, but i didn’t have to in this case. If someone has run into that problem and wants to post a link, to a good regex that you can use (should cover periods before and after, parenthesis, quotations etc.) then give a shout out in the comments.
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.