Extend the ActiveRecord::Base

Viewed 1664

If I make something like this:

class ActiveRecord::Base
  def self.encrypt(*attr_names)
    encrypter = Encrypter.new(attr_names)

    before_save encrypter
    after_save  encrypter
    after_find  encrypter

    define_method(:after_find) { }
  end
end
  1. Where do I have to save this file?
  2. Do it need to have a special name?
  3. Do I have to call require somewhere?
  4. Could I save it in the model folder?
  5. Is a class declared in the model folder visible from the other classes in the model folder without calling require?
1 Answers
Related