conditional before_safe

How to run before_safe only if a database field contains a certain value?

I tried:

before_save { |guest| guest.password = md5_pass(guest.password) , :if => :enabled? }

def enabled?
      self.deleted == 1
end

No success!

That shouldn't work. I think you are getting before_save confused with built-in validations. Try it like this:

before_save { |guest| guest.password = md5_pass(guest.password) if guest.enabled? }

Jochen Kaechelin wrote:

William Pratt schrieb:

That shouldn't work. I think you are getting before_save confused with built-in validations. Try it like this:

before_save { |guest| guest.password = md5_pass(guest.password) if guest.enabled? }

Ok, that's it! Thanx.