rabl icon indicating copy to clipboard operation
rabl copied to clipboard

Child node not printing, pretty stumped

Open dmastylo opened this issue 10 years ago • 6 comments

My rspec code: screen shot 2015-05-13 at 12 36 01 am

Rsepc result: screen shot 2015-05-13 at 12 36 54 am

As you can see, a team exists for the player in question, but is not being printed in the JSON. On the flip-side, the game node is being printed just fine.

Player/show code: screen shot 2015-05-13 at 12 39 14 am

rabl response

{
  "id": 1,
  "created_at": "2015-05-13T00:34:05.386-04:00",
  "game": {
    "id": 1,
    "name": "Game #<#<Class:0x007fd1f8f3e4c8>:0x007fd1f8f3de38>",
    "starts_at": "2015-05-16T00:34:05.328-04:00",
    "ends_at": "2015-05-16T03:34:05.328-04:00",
    "in_progress": false,
    "players": [
      {
        "player": {
          "id": 1,
          "username": "person28"
        }
      }
    ],
    "teams": [
      {
        "team": {
          "id": 1,
          "name": "990",
          "score": 0,
          "player_count": 1
        }
      },
      {
        "team": {
          "id": 2,
          "name": "469",
          "score": 0,
          "player_count": 0
        }
      }
    ]
  }
}

I have absolutely no idea what's wrong.

dmastylo avatar May 13 '15 04:05 dmastylo

What happens if you do:

node :team do |player|
  team = player.team
   { :id => team.id,  :name => team.name }
end

does that print out as expected? or how about:

child :team => :team do
  attributes :id 
end

anything?

nesquena avatar May 13 '15 04:05 nesquena

Looks like I'm running into even more issues. I tried adding extra attributes to the file but I'm still getting only the old ones??

screen shot 2015-05-13 at 12 52 23 am

{
  "id": 1,
  "created_at": "2015-05-13T00:52:34.307-04:00",
  "game": {
    "id": 1,
    "name": "Game #<#<Class:0x007fe14c5aafe8>:0x007fe14c5aab10>",
    "starts_at": "2015-05-17T00:52:34.232-04:00",
    "ends_at": "2015-05-17T03:52:34.232-04:00",
    "buy_in_price": 19,
    "max_players": 38,
    "in_progress": false,
    "players": [
      {
        "player": {
          "id": 1,
          "username": "person33"
        }
      }
    ],
    "teams": [
      {
        "team": {
          "id": 1,
          "name": "815",
          "score": 0,
          "player_count": 1
        }
      },
      {
        "team": {
          "id": 2,
          "name": "754",
          "score": 0,
          "player_count": 0
        }
      },
      {
        "team": {
          "id": 3,
          "name": "416",
          "score": 0,
          "player_count": 0
        }
      },
      {
        "team": {
          "id": 4,
          "name": "736",
          "score": 0,
          "player_count": 0
        }
      }
    ]
  }
}

dmastylo avatar May 13 '15 04:05 dmastylo

I believe this might have something to do with namespacing (I have an API::V1 and API::V2 namespace), but this is the first file where I've encountered the issue. My api/v1/games/show and api/v2/games/show have very different setups and they render correctly.

Even weirder... When I do

node :team do |player|
  team = player.team
   { :id => team.id,  :name => team.name }
end

If team is nil (the player doesn't have a team) then an exception is thrown that we're trying to call .id on nil, so it's obviously going through the right file... but the output is still not showing it when the team does exist.

I'm extremely stumped. This isn't happening anywhere else but this file.

dmastylo avatar May 13 '15 05:05 dmastylo

Okay, so I just tried doing it manually via cURL, everything worked as expected, all the nodes that I put in there worked. Then when I ran rspec, everything passes.

I cannot make this up. Have been pulling my hair out for 3 hours on this. Some sort of weird caching issue or something?? Christ.

dmastylo avatar May 13 '15 05:05 dmastylo

Sorry about this, that does sound frustrating...is everything working now?

nesquena avatar May 13 '15 14:05 nesquena

@nesquena No need to apologize, not your fault. As far as I know everything is working. I don't think this is a rabl issue unless the library is doing some caching under the hood. Really bizarre.

dmastylo avatar May 13 '15 17:05 dmastylo