ah, to_hash.
I guess I'm a ruby newbie :)

On Aug 2, 4:17 am, jonah honeyman <[email protected]> wrote:
> On Sun, Aug 01, 2010 at 08:19:21PM -0700, deco wrote:
> > There should be a better way of doing this.  5 lines is just too much
> > for ruby/dm
> >       @errors = Hash.new
> >       require 'dm-validations'
> >       @obj.errors.each_pair do |id, error|
> >         @errors[id] = error.to_s
> >       end
> >       @errors.to_json
>
> > if I just use @obj.errors.to_json it gives me an array instead of a
> > hash (so I just have the errors strings without the key/field that it
> > pertains to).
>
> > Any suggestions?
>
> Well, I can think of several ways that may suit your purposes.
>
>     DataMapper::Validate::ValidationErrors.class_eval{
>       def to_json; to_hash.to_json end
>     }
>
> or what I generally use:
>
>     @obj.errors.to_hash.to_json
>
> There may be better alternatives.
>
>
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "DataMapper" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to 
> > [email protected].
> > For more options, visit this group 
> > athttp://groups.google.com/group/datamapper?hl=en.
>
> --
> -jonah

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to