ewanmcdougall-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2008-Mar-05 15:23 UTC
validate_on_update compare old value to new value
Hello, After a model has been saved I want to prevent some of it''s fields from being updated. I was going to do this by overriding validate_on_update but I don''t know how to access the old value to compare it to the new value. Cheers, Ewan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ewanmcdougall-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org wrote:> Hello, > After a model has been saved I want to prevent some of it''s fields > from being updated. I was going to do this by overriding > validate_on_update but I don''t know how to access the old value to > compare it to the new value. > Cheers, > Ewan >How about overriding the setter methods for those fields you want to lock. Something like... def title=(t) self[:title] = t if self.new_record? end -- http://www.5valleys.com/ http://www.workingwithrails.com/person/8078 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ewanmcdougall-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2008-Mar-06 18:09 UTC
Re: validate_on_update compare old value to new value
Hello Jon, Thanks for the reply. I made the attribute read only doing attr_readonly :title Ewan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---