title: Ruby on Rails - Share one method with 2 models
body: <p>I have the following module</p>
  
  <pre><code>module SharedMethods
  
      # Class method
      module ClassMethods
  
          #
          # Remove white space from end of strings
          def remove_whitespace
              self.attributes.each do |key,value|
                  if value.kind_of?(String) &amp;&amp; !value.blank?
                      write_attribute key, value.strip
                  end
              end
          end
  
  
      end
  
      #
      #
      def self.included(base)
          base.extend(ClassMethods)
      end
  
  end
  </code></pre>
  
  <p>and I am using it in my models like</p>
  
  <pre><code>include SharedMethods
  before_validation :remove_whitespace
  </code></pre>
  
  <p>However whenever I submit the form I get a  "undefined method `remove_whitespace'" message</p>
  
  <p>What can I do to correct this error?</p>