mhgbrown / cached_resource

Caching for ActiveResource
MIT License
80 stars 28 forks source link

Error: undefined class/module #6

Closed sivicencio closed 11 years ago

sivicencio commented 11 years ago

Hello. I've encountered with this when I've tried to cache an Active Resource model that includes an array as a field. The error is:

"undefined class/module Place::Child"

And the resource json response is:

[
    {
        "id" : 1,
        "name" : "Chile",
        "children": [
            {
                "id": 3,
                "name": "Metropolitana"
            },
            {
                "id": 4,
                "name": "Valparaíso"
            }
        ]
    },
    {
        "id" : 2,
        "name" : "Colombia",
        "children": [
            {
                "id": 5,
                "name": "Bogotá"
            },
            {
                "id": 6,
                "name": "Cartagena de Indias"
            }
        ]
    }
]

The "children" field is recognized as a class, not just as a simple field. Is there a way to avoid this?

mhgbrown commented 11 years ago

Hi Sebastián, I don't have any immediate ideas, but I can take a look at it later. And just FYI, I am looking to move this project over to my github and update it to work with Rails 4 sometime in the near-ish future.

sivicencio commented 11 years ago

Great news! It's very useful if you're using Active Resource, so thank you for having the intention to make it work with Rails 4.

I've come with a solution: just added the next code inside my Place model (ApplicationResource is a class that inherits from ActiveResource::Base)

class Child < ApplicationResource
end
mhgbrown commented 11 years ago

I'm going to go ahead and close this since it seems like a solution has been found.