我正在使用 ember-data 和 rails 作为 API 构建 Ember 应用程序。我正在尝试从 application.js 文件中调用 BusinessNotifications 模型的 find 方法。进行初始调用时,我收到“没有方法'find'”错误。
我的 application.js 文件:
//= require jquery
//= require jquery_ujs
// require jquery.ui.all
//= require handlebars
//= require ember
//= require ember-data
//= require ember-auth
//= require_self
//= require auth
//= require company_backend
//= require ./wepay
//= require_tree .
//= stub polyfills/aight.js
//= stub polyfills/aight.d3.js
//= stub polyfills/mediaqueries.js
//= stub polyfills/pointerevents.js
//= stub polyfills/svg.js
window.CompanyBackend = Em.Application.create({
ready: function() {
var BusinessNotifications = CompanyBackend.BusinessNotification.find();
setInterval(function() {
BusinessNotifications.reload();
}, 2000);
},
});
我的模型:
CompanyBackend.BusinessNotification = DS.Model.extend({
notification: DS.attr('string'),
timeSeen: DS.attr('integer'),
active: DS.attr('boolean'),
type: DS.attr('string'),
});
我的序列化器:
class BusinessNotificationSerializer < BaseSerializer
attributes :id, :business_id, :notification, :time_seen, :active, :type
end
我的路线:
CompanyBackend.BusinessNotificationRoute = Em.Route.extend({
model: function() {
return CompanyBackend.BusinessNotification.find();
},
});
我的路由器.js:
this.resource('business_notification', { path: '/' });
我在 rails 端设置了控制器和路线,但这些应该是无关紧要的,否则我会在控制台中遇到某种 rails 错误。
谢谢您的帮助!