Problem with active record and the before_save filter
I have this code in my model, but something is not working as I expected.
   before_save :destroy_image?, :no_spaces_in_telephone
   def no_spaces_in_telephone
     self.phone.gsub! /\s+/, 'XXX'
     ABLog "Telefono", self.phone
   end
   def ABLog tag, string
     logger.info "\n\n#### #{tag} : \n " + string.to_s + "\n\n"
   end
The Log prints the phone with "XXX" in place of white spaces, but my record does not get updated, and the phone remains the same, with all the withes paces in their place.
What am I doi开发者_运维技巧ng wrong?
def no_spaces_in_telephone
     self.phone = self.phone.gsub /\s+/, 'XXX'
     ABLog "Telefono", self.phone
end
This is because self.phone= is a method.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论