I wan''t to make my custom validation before saving an object. 1. Why doesn''t this work? class User < ActiveRecord::Base .... def validate self.errors.add( ''name'', ''your name is always wrong!'' ) end ... end (I get no error, but i still save the object) 2. i) Why is this working? class User < ActiveRecord::Base .... validate do | record | record.errors.add( ''name'', ''your name is always wrong!'' ) end ... end ii) What is ''validate''? Is not a method of class ''User'' because it''s not prefixed with ''def'' (i.e. def validate ... end) 3. thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mea culpa. Version 1 works. Still have 2. dilemma George wrote:> I wan''t to make my custom validation before saving an object. > > 1. Why doesn''t this work? > class User < ActiveRecord::Base > .... > def validate > self.errors.add( ''name'', ''your name is always wrong!'' ) > end > ... > end > (I get no error, but i still save the object) > > 2. i) Why is this working? > class User < ActiveRecord::Base > .... > validate do | record | > record.errors.add( ''name'', ''your name is always wrong!'' ) > end > ... > end > ii) What is ''validate''? Is not a method of class ''User'' because it''s not > prefixed with ''def'' (i.e. def validate ... end) > > 3. thanks-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---