Thomas Allen
2010-Apr-28 16:16 UTC
ActiveResource does not detect errors for my very simple model
The documentation says to return a code 422 with a packet in the following format: <errors type="array"><error>First cannot be empty</error></errors> So that is what I am doing. But my model will not raise an exception on a create call that returns such a response, and a record created that way returns true for its valid? call. I simply do:>> Menu.createWhich triggers validation errors in the other application, which responds with 422 and the following packet, because a "name" field is required: <errors type="array"> <error>Name cannot be empty</error> </errors> Why would ActiveResource interpret such a response as valid? Is there something more I need to do in my model for validations to take effect? My models themselves are dead simple: class ApplicationResource < ActiveResource::Base self.site = ''http://localhost/frontend/www/api'' end class Menu < ApplicationResource end Thomas -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thomas Allen
2010-Apr-28 16:29 UTC
Re: ActiveResource does not detect errors for my very simple model
I referred to http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/67d59a432f1d98e3 and tried this with Rails 2.2.2, but got the same result. I am guessing the issue I am experiencing is not version-specific. Thomas On Apr 28, 12:16 pm, Thomas Allen <thomasmal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The documentation says to return a code 422 with a packet in the > following format: > > <errors type="array"><error>First cannot be empty</error></errors> > > So that is what I am doing. But my model will not raise an exception > on a create call that returns such a response, and a record created > that way returns true for its valid? call. > > I simply do: > > >> Menu.create > > Which triggers validation errors in the other application, which > responds with 422 and the following packet, because a "name" field is > required: > > <errors type="array"> > <error>Name cannot be empty</error> > </errors> > > Why would ActiveResource interpret such a response as valid? Is there > something more I need to do in my model for validations to take > effect? My models themselves are dead simple: > > class ApplicationResource < ActiveResource::Base > self.site = ''http://localhost/frontend/www/api'' > end > > class Menu < ApplicationResource > end > > Thomas > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.