Ember CLI not using two separate JSON calls for model's index and list views


#1

I have a “Post” model in my Ember CLI app with two routes:

  • An “index” route (for a list of all of the posts)
  • A “view” route (to view a single post).

My index route calls “/posts” and pulls in the JSON data that looks like this:

{
  "posts": [
    {
      "id": 1,
      "title": "Post One"
    },
    {
      "id": 2,
      "title": "Post Two"
    },
    {
      "id": 3,
      "title": "Post Three"
    }
  ]
}

As I understand the REST Adapter, my view route should call /posts/[id], which looks like this:

{
  "post": {
    "id": 1,
    "title": "Post One",
    "body": "<p>Lorem ipsum dolor sit amet.<\/p>"
  }
}

However, when I use {{body}} in my view template, it outputs undefined. When I add the body field to my /posts data it shows up correctly.

Is there a reason why my /posts/[id] data isn’t getting used for my view page, but it’s using the /posts/ data instead?


#2

Oddly enough, if I manually refresh a post’s view template the content shows up with no issues. It’s only when clicking from the index page to a post that {{body}} renders undefined.

I also noticed that clicking a post from index doesn’t fetch the /posts/[id] page in the Network tab in Dev Tools.