2

I have a Court.rb model (inheriting from Active Record) in my Rails app that I'm also using with ember-rails gem.

I created a Court model for it in Ember

 App.Court = DS.Model.extend({
    jurisdictionId: DS.attr('number'),
    name: DS.attr('string')
  });

There is a courts resource in the router

  App.Router.map(function() {
    this.resource("courts");
    this.resource("about");

  });

and, to retrieve the data, I created a courts route that calls findAll() on the Court model

App.CourtsRoute = Ember.Route.extend({
  model: function() {
    return App.Court.findAll();
  }

});

Ember's giving me a long error message for this, the final part of which says has no method 'findAll' . I also tried to use App.Court.find() and got the same error.

This is essentially what Ryan Bates did to retrieve data from the server in his Railscast on Ember He created an Entry model

Raffler.Entry = DS.Model.extend({
  name: DS.attr('string'),
  winner: DS.attr('boolean')
});

And also an Entries route that calls find on the model

 Raffler.EntriesRoute = Ember.Route.extend

  model:  -> Raffler.Entry.find()

Can you explain what I might be doing wrong to get this to work?

3
  • Which version of Ember/Ember Data are you using? Commented Sep 8, 2013 at 17:01
  • @kroofy I ran this command yesterday to get the latest version rails generate ember:install --head whatever that is. Commented Sep 8, 2013 at 17:03
  • Try using return this.store.find('court'); in the model hook Commented Sep 8, 2013 at 17:13

1 Answer 1

3

You are probably running the latest version of Ember Data,

Try using:

return this.store.find('court'); instead of return App.Court.findAll();

Here's a jsfiddle showing a simple structure: http://jsfiddle.net/XUmTC/2/

For more information of the transition look here: https://github.com/emberjs/data/blob/master/TRANSITION.md

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for trying but it gave me an error. Assertion failed: The response from a findAll must be an Array, not {courts: [object Object],[object Object],[object Object]... I thought Ember needed the root courts (in this case) in the json returned from server. Is that the problem do you think?
It should use the root key courts, maybe the JSON is not formatted correctly? Can you make a JSfiddle with fixture data?
I tried to adapt someone else's Ember fiddle with some fixture data but I couldn't figure out how to get it to work. However, you can see the fixture data here along with the code I added. jsfiddle.net/backyardguy/PkT8x/365
Added a fiddle to it. So if that's not working for you when you switch to real backend, it could be that the data is not properly formatted.
thanks a lot. I thought the data that Ember expects JSON data to have the root (in this case 'courts'), but you removed it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.