Reputation: 4796
In which file could I add a new method to a common class, like String, Array etc, so that all models can reuse the method?
For example, in user.rb I can define:
class String
def strip_non_word_chars
self.gsub!(/(\W)/," ")
end
end
class User < ActiveRecord::Base
end
But other models cannot use the new strip_non_word_chars method. I want it to be useable by all models...
Upvotes: 0
Views: 311
Reputation: 6642
I believe one place would be in an initializer file in the config/initializers
directory. Although I'm not sure if this is common for your task.
Upvotes: 2