Forum: Ruby on Rails Including a Module within a model

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0f1e2ec122971063c71677aa03bfe038?d=identicon&s=25 Oliver Legg (Guest)
on 2006-02-13 17:04
(Received via mailing list)
If I have a module with a callback in it:

module Sanitize
   module PhoneNumber
     def before_validation
       self.phone.gsub!(/\D/, '') if attribute_present?('phone')
     end
   end

   module MobileNumber
     def before_validation
       self.mobile.gsub!(/\D/, '') if attribute_present?('mobile')
     end
   end
end

and then I include that within my model:

class Contact < ActiveRecord::Base
   include Sanitize::PhoneNumber
end

Why doesn't it work?? Any ideas?
This topic is locked and can not be replied to.