ccocchi / rabl-rails

Rails 4.2+ templating system with JSON, XML and Plist support.
MIT License
209 stars 51 forks source link

Polymorphic Association #47

Open HassanJ opened 10 years ago

HassanJ commented 10 years ago

I have been using Rabl and I thought I should give rabl-rails a try as it promises faster responses. I am using public_activity gem which has a polymorphic belongs_to belongs_to :trackable, :polymorphic => true

When I use child :trackable while using rabl, everything works as expected, and the key of the child object is actually the model name. But in rabl-rails the key comes as it is, i-e 'trackable' and its empty.

An example with rable

{
    "type": "Event",
    "users": [{
        "id": 898,
    }],
    "time": "2013-09-10T15:31:12Z",
    "event": {
        "id": 27,
        "name": "Hold it",
    }
}

with rabl-rails

{
    "type": "Event",
    "users": [{
        "id": 898,
    }],
    "time": "2013-09-10T15:31:12Z",
    "trackable": null
}