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! -- Jochen Kaechelin railswerk.de, gissmoh.de, figgfrosch.de, ror-ror.de --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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:> 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! > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. -- Jochen Kaechelin railswerk.de, gissmoh.de, figgfrosch.de, ror-ror.de --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---