1

I've taken over a slightly broken ember project, but I can't get even the most basic model to work. I've commented out all of the code of the former project, and have basically just this:

App = Ember.Application.create();

App.ApplicationAdapter = DS.FixtureAdapter.extend

App.Admin = DS.Model.extend(
  userName: DS.attr("string")
  roles: DS.attr("string")
)

App.Admin.FIXTURES = [
  {
    userName: 'Tester One'
    roles: 'six-sided die'
  }
  {
    userName: 'Tester Two'
    roles: 'four-sided die'
  }
]

App.Router.map ->
  @route 'about', { path: '/about' }
  @resource 'admins', { path: '/admins' }

App.AdminsRoute = Ember.Route.extend
  model: ->
    return @store.find('admin')

It's built inside of a Rails 4.0.1 app (running 0.14.1 of ember-rails and 1.3.2 of ember-source). When I go to the root page, I see the proper ember template. When I click on the link for about, I get routed to the about template. But when I click on admins or go to /admins, instead of having it render the admins template (which is just some static text), I get this error in my js console:

Error while loading route: TypeError: Object function () {
    var Class = makeCtor(), proto;
    Class.ClassMixin = Mixin.create(this.ClassMixin);
    Class.PrototypeMixin = Mixin.create(this.PrototypeMixin);

    Class.ClassMixin.ownerConstructor = Class;
    Class.PrototypeMixin.o...<omitted>... } has no method 'create'

followed by a bunch of backtraces inside the ember code. I don't call create anywhere, and it was giving a similar error for the other models in the app that I've (since) commented out. I've tried to build this following the ember guide as something that would work for sure.

The Ember inspector sees an admins route named AdminsRoute using the AdminsController and admins template at /admins.

Simply put, I don't know how to debug this any further.

I've tried several versions of ember/-data, but currently I'm using 1.4.0-beta.6 and 1.0.0-beta.6 and getting this error still.

Thanks!

1
  • Restart Chrome and the error is different: Error while loading route: TypeError: undefined is not a function. Try on Firefox and the error is different still: Error while loading route: instantiate@http://localhost:3000/ etc. Commented Feb 9, 2014 at 20:53

4 Answers 4

3

This is a common mistake when using coffeescript with ember, you have to update

App.ApplicationAdapter = DS.FixtureAdapter.extend

to

App.ApplicationAdapter = DS.FixtureAdapter.extend()

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

1 Comment

That seems to have done the trick. Thanks. But I'll use the DS.Store.extend… adapter syntax going forward.
0

Could it be the missing comma?

App.Admin.FIXTURES = [
  {
    userName: 'Tester One'
    roles: 'six-sided die'
  }
  {
    userName: 'Tester Two'
    roles: 'four-sided die'
  }
]

to

App.Admin.FIXTURES = [
  {
    userName: 'Tester One'
    roles: 'six-sided die'
  },
  {
    userName: 'Tester Two'
    roles: 'four-sided die'
  }
]

1 Comment

Thanks, but I tried that, too. In CoffeeScript, those commas are optional.
0

Try giving the models in your fixtures a unique id

1 Comment

This was necessary once the server saw the models. When I posted the query, I hadn't even gotten that far yet! Thanks!
0

I suspected something might be up with the upgrade process, and it was an imperfect implementation of the store.

store.coffee had read simply:

App.ApplicationAdapter = DS.FixtureAdapter.extend

I changed that to:

App.Store = DS.Store.extend
  adapter:DS.FixtureAdapter

And it worked fine (though I did have to add ids, as @chopper noted). Seeing as we'll be using an api for the store, I'll stick to this variant, though @marcio-junior's suggestion also worked! Thanks!

Comments

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.