What is the preferred way to Monkey Patch in Rails 3?
I just want to add a method to the String class. I’m more looking at where to place the file.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The initializer directory is a good place to collect all those little scraps. Since I tend to go a bit overboard with core extensions, I like to make a folder there called “extensions” and toss them all in there.
So, try
/config/initializers/string_extension.rb, or/config/initializers/extensions/string.rb, or something similar. Either way, you can just forget about them afterward – Rails will require them for you, so you don’t need to do it yourself.