Use super with before_validation.

Posted by krunal shah on Stack Overflow See other posts from Stack Overflow or by krunal shah
Published on 2010-06-11T19:42:38Z Indexed on 2010/06/11 19:52 UTC
Read the original article Hit count: 501

Filed under:
|
 I have this code in my every model.
 Class people
   def before_validation
    @attributes.each do |key,value|
      self[key] = nil if value.blank?
    end
   end
 end

 Now i want to put my loop in separate module. Like
 Module test
   def before_validation
     @attributes.each do |key,value|
      self[key] = nil if value.blank?
     end
   end
 end

 And i want to call this before_validation this way
 Class people
   include test
   def before_validation
     super
     .....Here is my other logic part..... 
   end
 end

 Are there any way to do it like that in rails??

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby