mribbons/ember-todo-with-rails — pull request #4 by thenickcox (2014-03-31 04:02:55+00:00)
Title: Refactor todo controller to serialize JSON properly (fixes #2)

This PR adds the `inherited_resources` gem, which effectively removes much of the current controller.

When I was saving a todo, I got the error that it was sending the key `id`, but I didn't have a mapping for it. It turns out the JSON that was returned was this:

```json
{id:66, title:try this, is_completed:false}
```

But Ember expected there to be a root element, like so:

```json
{todo: {id:66, title:try this, is_completed:false}}
```

`inherited_resources` and `active_model_serializers` play really nicely together. I had remembered from another project that it used `inherited_resources`, and I didn't remember getting that JSON serialization error. So this fixes that.

I also noticed that the serializer in this project was called `TodosSerializer`, while Rails was looking for a serializer called `TodoSerializer`, in the singular, like the model. (See (this section of the AMS docs)[https://github.com/rails-api/active_model_serializers#render-json]). So I changed that, but the error still didn't go away.

However, `inherited_resources` fixed the issue. And it removed a lot of code for free. I tried to dig into the source to figure out why it wasn't working before, but `inherited_resources` is pretty tough to figure out. In any case, this fixes #3.