开发者

Problem with active record and the before_save filter

开发者 https://www.devze.com 2023-03-26 09:31 出处:网络
I have this code in my model, but something is not working as I expected. before_save :destroy_image?, :no_spaces_in_telephone

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消