Ruby on Rails Saturday, February 1, 2014



On Thursday, January 30, 2014 9:49:41 PM UTC, Ruby-Forum.com User wrote:

[{"id":2, "name":"foo"}, {"id":3, "name":"bar"...

no root elements.  Using the active record serializers I've gotten some
flexibility in specifying the root element, but now I either end up with
the above (no root element) or:

{"scholarships":["scholarships":{"id", 2....

where I get a root element for the whole Array that is then added to
every element.

Is anybody still with me and can help me unwind this?  When rendering
the json for a scholarhip I need to specify the "scholarship" root tag
... and when rendering a collection of Scholarships I need to be able to
override and NOT show a root tag?


Have you tried playing with the include_root_in_json setting?

If it comes to it you could always override as_json in your model or use something like jbuilder to construct your json explicitly

Fred

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4cd71ec8-40bc-4414-b6b7-7628927e3957%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment