0
votes

I'm building an Ember application using ember-data and rails as an API. I'm trying to call a find method on a BusinessNotifications model from the application.js file. When making the initial call I get the "has no method 'find'" error.

My application.js file:

//= 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);
    },
});

My Model:

CompanyBackend.BusinessNotification = DS.Model.extend({
  notification: DS.attr('string'),
  timeSeen: DS.attr('integer'),
  active: DS.attr('boolean'),
  type: DS.attr('string'),
});

My Serializer:

class BusinessNotificationSerializer < BaseSerializer
  attributes :id, :business_id, :notification, :time_seen, :active, :type
end

My Route:

CompanyBackend.BusinessNotificationRoute = Em.Route.extend({
  model: function() {
    return CompanyBackend.BusinessNotification.find();
  },
});

my router.js:

this.resource('business_notification', { path: '/' });

I have the controller and the route set up on the rails end, but those should be irrelevant or I would be getting some sort of rails error in the console.

Thanks for the help!

1

1 Answers

0
votes

This problem happen because probally you are using the 1.0.0-beta.X versions. And your code is using the v0.14 or v0.13 api.

You have 2 choices:

1- You can update your code to use the 1.0.0-beta.3, this transition guide point the changes needed. Your code will become:

Ember.Application.initializer({
  name: "reload-busisness-notifications",

  initialize: function(container, application) {
    var store = container.lookup('store:main')
    var BusinessNotifications = store.find('businessNotification')     
    setInterval(function() {
      BusinessNotifications.update();
    }, 2000);
  }
});

The initializer isn't madatory but I think it's a good idea because you have access to container, without use BusinessNotifications.__container__

2- You can get the v0.14 version here, and replace by your current.