# EmberCLI + Rails API

**URL:** <https://discuss.emberjs.com/t/embercli-rails-api/10456>\
**Category:** Uncategorized\
**Created:** [April 16, 2016, 4:53pm UTC](https://discuss.emberjs.com/t/embercli-rails-api/10456 "2016-04-16T16:53:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![r0uder](https://avatars.discourse-cdn.com/v4/letter/r/7ab992/32.png) [@r0uder](https://discuss.emberjs.com/u/r0uder)\
**Post date:** [April 16, 2016, 4:53pm UTC](https://discuss.emberjs.com/t/embercli-rails-api/10456/1 "2016-04-16T16:53:44Z")

</div>

I’m trying to get to work EmberCLI frontend app with my Rails API. For some reason it does not work. When I visit ‘localhost:4200/artists’ I see nothing but h1 tag. No API data. JS Console is empty. Any ideas?

Here’s my adapter:

```
import JSONAPIAdapter from 'ember-data/adapters/json-api';

export default JSONAPIAdapter.extend({
  host: 'http://localhost:3000'
});

```

Model:

```
import DS from 'ember-data';

export default DS.Model.extend({
  name: DS.attr('string'),
  itunes_id: DS.attr('integer'),

});

```

Router:

```
import Ember from 'ember';
import config from './config/environment';

const Router = Ember.Router.extend({
  location: config.locationType
});

Router.map(function() {
  this.route('artists');
});

export default Router;

```

Route:

```
import Ember from 'ember';

export default Ember.Route.extend({
  model() {
    return this.store.findAll('artist');
  }
});

```

And view:

```
<h1> Artists </h1>
    <ul>
      {{#each artists as |artist|}}
        <li>Hello, {{artist.name}}!</li>
      {{/each}}
    </ul>

```

---

<div class="post-metadata">

**Author:** ![nicolasd](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/nicolasd/32/10089_2.png) [@nicolasd](https://discuss.emberjs.com/u/nicolasd)\
**Post date:** [April 16, 2016, 9:42pm UTC](https://discuss.emberjs.com/t/embercli-rails-api/10456/2 "2016-04-16T21:42:03Z")

</div>

Hey, have you also set the host and namespace right for your rails API in the `adapters/application.js`? Here is the link to the docs: [Connecting to an HTTP Server - Models - Ember Guides](https://guides.emberjs.com/v1.10.0/models/connecting-to-an-http-server/#toc_customizing-the-adapter)

If your Rails API is on `localhost:3000` (at least in local development) and you have your routes under the namespace `/api`, your `adapters/application.js` should look like this:

```
App.PostAdapter = DS.RESTAdapter.extend({
  namespace: 'api',
  host: 'https://localhost:3000'
});

```

---

<div class="post-metadata">

**Author:** ![r0uder](https://avatars.discourse-cdn.com/v4/letter/r/7ab992/32.png) [@r0uder](https://discuss.emberjs.com/u/r0uder)\
**Post date:** [April 17, 2016, 6:56am UTC](https://discuss.emberjs.com/t/embercli-rails-api/10456/3 "2016-04-17T06:56:07Z")

</div>

Hello, thank you for your reply.

I have it, my bad I forgot to put it here.

Considering that I have it all and it still doesn’t work, maybe there’s something wrong with my backend?

---

<div class="post-metadata">

**Author:** ![nicolasd](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/nicolasd/32/10089_2.png) [@nicolasd](https://discuss.emberjs.com/u/nicolasd)\
**Post date:** [April 17, 2016, 7:42am UTC](https://discuss.emberjs.com/t/embercli-rails-api/10456/4 "2016-04-17T07:42:34Z")

</div>

Your template is wrong, you have to loop over `model` and not artist 🙂

```
{{#each model as |artist|}}
      Hello, {{artist.name}}
{{/each}}

```

This is also the reason why you don’t get any errors in the console. Since the template doesn’t use `model`, you don’t resolve the promise.

To prevent this in the future: I’d have debugged this with `{{log artists}}` in my template. Then I’d have seen that `{{artists}}` is empty and so on… Hope this helps now!

---

<div class="post-metadata">

**Author:** ![r0uder](https://avatars.discourse-cdn.com/v4/letter/r/7ab992/32.png) [@r0uder](https://discuss.emberjs.com/u/r0uder)\
**Post date:** [April 17, 2016, 5:12pm UTC](https://discuss.emberjs.com/t/embercli-rails-api/10456/5 "2016-04-17T17:12:25Z")

</div>

Thank you man, made my day.
