Forum: Ruby on Rails to_json and polymorphic models

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jif (Guest)
on 2007-07-07 00:32
(Received via mailing list)
I have tried to use to_json to create an array that will be
manipulated in javascript on the client.  The output of to_json looks
something like this:

  {attributes: {code: "123123123", quantity: "123", id: "1",
description: "Window", unit_price: "12"}},
   attributes: {addressable_type: "WorkshopOrderPart",
workshop_order_id: "1", addressable_id: "1", id: "1", position:
{addressable: ...

You will notice that "attibutes" shows up twice due to the polymorphic
relationship but is not a range so if you assign it to a javascript
array then addressing it goes like this:


That works but:


does not.  Anyone know how to go about addressing the "attributes"?
This topic is locked and can not be replied to.