Closed vanso-hubsi closed 9 years ago
The only reason may be it's quite common for REST responses to contain an error key. Maybe the method should be _errors so it doesn't conflict with an errors key from the response? Or maybe have #errors also work, if there was no such key. I'll have a look in to this.
If you can test the latest github version, see if that works for you? If so, I'll release it as a new version as it's interface compatible.
Thanks for the ultra quick response!
Maybe the method should be _errors so it doesn't conflict with an errors key from the response?
I don't think so, since "errors" is the error hash name commonly used in ActiveRecord. If the response should contain an errors key, I think you could rewrite it with a proxy.
The latest github version works for me, it's exactly the same change as what I did locally.
But I'm wondering if I'm really the only one trying to read the errors from validations?! Cause from the commit history it looks like this hasn't been working for a longer time... (And perhaps the validation spec tests should be modified to not use a struct but a real ActiveRestClient::Base object?)
Anyways, it's working now, so I'm going to close this issue.
Oops, I didn't see that you renamed the errors
method to _errors
. This basically makes the errors thing work, but I can't use the ActiveRestClient objects in my views the same way as ActiveRecord objects. I have a helper function that checks for object.errors.any?
which now doesn't work for ActiveRestClient objects anymore.
Don't you think that your model should be as close as possible to ActiveRecord?
Well, don't bother. I just found that I can't use my helper function anyways, as I'm using ActiveRecord::Errors specific calls, which is the errors type for ActiveRecord objects.
We aim for it to be as close as possible, but there are some differences as we're potentially accessing a wider variety of "databases" ;-)
No to worry, sorry the quick response didn't help you in the end.
No to worry, sorry the quick response didn't help you in the end.
It did help me: By calling _errors
I'm now able to access the validation errors at all, which I wasn't before. Or was I?
No, you're right, I think it had been broken a while. I guess no-one was using the validations :-)
Hi! Thanks for this helpful gem which helped me a lot to quickly create a REST-based model.
With basic requests working I now wanted to carry on with error handling. I wanted to use active-rest-client's validation capability, when I got stuck with not being able to access the errors hashmap.
In short, this didn't work:
I wondered why, because both
valid?
anderrors
are defined invalidation.rb
, but somehow I wasn't able to use theerrors
method. It wasn't in the list ofrestobject.methods
either, so I started digging and found that theerrors
method seems to get undefined inbase.rb:L14
. When I removederrors
from the array, all started working as expected.I'm no ruby/rails expert, but to me it looks like a bug. Or is it me doing something wrong?