
[PATCH] dm-serializer support for ValidationErrors
Reported by Martin Gamsjaeger (snusnu) | December 17th, 2008 @ 02:50 PM
Hey,
I just added the possibility for dm-serializer to serialize DataMapper::Validate::ValidationErrors objects.
This makes it possible now to do
display @article.errors, :status => 422
for :xml, :json, :yaml and :csv
However, I encountered a weird problem while writing #to_json. I initially wanted the #to_json method to simply look like:
def to_json(*args)
opts = args.first || {}
errors.to_json(opts) # errors is a Hash here
end
because I thought that this should do the trick (it actually works when playing in irb).
However, I always got wrong argument type Hash (expected Data) - (TypeError) when calling #to_json on the errors Hash.
I googled a bit, didn't really find a workaround (i tried the advice on http://blog.idearise.com/2008/09... ... no success) and so I decided to implement #to_json by hand. Which means it's probably buggy :-)
I'm sorry I haven't written any specs for it (yet). I did test it in the usecase where I needed it, though, and everything seems to work fine.
Also, there are still some comments inside the patch. If everything is fine, I'll be happy to clean it up and submit it again (later on today or on monday, I leave for a short skiing trip tommorrow, hooray :-)
cheers snusnu
Comments and changes to this ticket
-
Xavier Shay December 31st, 2008 @ 01:32 PM
- State changed from unconfirmed to accepted
- Assigned user set to Xavier Shay
Sorry for the delay, I will investigate this
-
Xavier Shay December 31st, 2008 @ 07:22 PM
Good idea, please spec it out :)
This won't apply cleanly against trunk coz the methods have been split out into their own files.
It looks like a similar to_json hack has been used for Collection support, so just run with yours for the moment, I'll play with it more thoroughly when we've got a specced out patch.
-
Xavier Shay June 19th, 2009 @ 10:10 PM
Fixed in http://github.com/xaviershay/dm-more/tree/718-serializer-support-fo... (Also includes fix for #829, coz it depends on it)
-
Dan Kubb (dkubb) June 23rd, 2009 @ 12:30 AM
- State changed from accepted to resolved
(from [552ea90e0b48b5c3525d67c0afb64b3d89a18174]) [dm-serializer] Add support for serializing errors from dm-validations
This is neat because now you can do:
display @article.errors, :status => 422props to Martin Gamsjaeger (snusnu) for the meat of this patch
[#718 state:resolved] http://github.com/datamapper/dm-more/commit/552ea90e0b48b5c3525d67c...
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
Attachments
Referenced by
-
718 [PATCH] dm-serializer support for ValidationErrors [#718 state:resolved] http://github.com/datamapper/dm-mo...