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!
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()
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'
}
]
尝试给你的灯具中的模型一个唯一的ID
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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.