I have a Rails api that I want to render to an Ember application. I have a question model that looks like
import DS from 'ember-data';
export default DS.Model.extend({
body: DS.attr('string'),
response: DS.attr('string')
});
The api can render a bunch of questions on the api/v1/questions.json url. I want to grab this data to use in ember. In my route folder I have namespaced index and random. My random route returns a random question and works well when I go to the questions/random route:
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findRecord('question', 'random.json');
}
});
In the terminal where I'm running my Rails server, app starts a GET request as
Started GET "/api/v1/questions/random.json" for 127.0.0.1
I've set up my index route in a similar fashion, but this time I'm returning a collection of questions
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('question', 'questions.json');
}
});
In the terminal where I'm running my Rails server, the call goes in as
Started GET "/api/v1/questions" for 127.0.0.1
I'm expecting it to be /api/v1/questions.json but it isn't. No data is being fetched. I've taken a look on the ember docs and tried variations on findRecord, peekAll, etc. The data that I'm requesting (or want to be returned to me) is a collection of question objects but not all of the objects from the api.
I'm wondering why the .json portion that I've specified is not being sent along in my api call.
api/v1/questions
that's ember-data convention. andthis.store.findAll('question')
is enough. you don't need to pass an argument in your case.findRecord
second argument is an id to search. – Ember Freak