how do i add errors manually to an object so they show up in the same list as the validations? i tried errors.add - and it adds the error, but it doesn''t stop the object from being saved like a validates_presence_of would -- 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 -~----------~----~----~----~------~----~------~--~---
Jimmy Palmer wrote:> how do i add errors manually to an object so they show up in the same > list as the validations? > > i tried errors.add - and it adds the error, but it doesn''t stop the > object from being saved like a validates_presence_of woulddefine your own validate() method in your model, the errors you add there will show up and a failure will prevent the save. hth ilan -- 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 -~----------~----~----~----~------~----~------~--~---
Ilan Berci wrote:> Jimmy Palmer wrote: >> how do i add errors manually to an object so they show up in the same >> list as the validations? >> >> i tried errors.add - and it adds the error, but it doesn''t stop the >> object from being saved like a validates_presence_of would > > define your own validate() method in your model, the errors you add > there will show up and a failure will prevent the save. > > hth > > ilancan you further explain how I might do this? -- 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 -~----------~----~----~----~------~----~------~--~---
Jimmy Palmer wrote:> Ilan Berci wrote: >> Jimmy Palmer wrote: >>> how do i add errors manually to an object so they show up in the same >>> list as the validations? >>> >>> i tried errors.add - and it adds the error, but it doesn''t stop the >>> object from being saved like a validates_presence_of would >> >> define your own validate() method in your model, the errors you add >> there will show up and a failure will prevent the save. >> >> hth >> >> ilan > > can you further explain how I might do this?class SomeModel < ActiveRecord::Base def validate errors.add(:world, "the world is not flat!") if self.world.flat? end end -- 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 -~----------~----~----~----~------~----~------~--~---
Ilan Berci wrote:> Jimmy Palmer wrote: >> Ilan Berci wrote: >>> Jimmy Palmer wrote: >>>> how do i add errors manually to an object so they show up in the same >>>> list as the validations? >>>> >>>> i tried errors.add - and it adds the error, but it doesn''t stop the >>>> object from being saved like a validates_presence_of would >>> >>> define your own validate() method in your model, the errors you add >>> there will show up and a failure will prevent the save. >>> >>> hth >>> >>> ilan >> >> can you further explain how I might do this? > > class SomeModel < ActiveRecord::Base > > def validate > errors.add(:world, "the world is not flat!") if self.world.flat? > end > endyeah, I tried that, but it still did not display the error and allowed the object to save. Do I need to manually check if there are errors and manually display them? -- 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 -~----------~----~----~----~------~----~------~--~---