开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜