1

I am using a Rails API to return JSON that I then use in my Entity model in an Ember app. While this works fine on localhost it is not working when I deploy the app to Heroku; it shows this error on the console:

"Error while loading route: entities" "e.addArrayObserver is not a function" 
"P<._setupArrangedContent@http://myappadress.herokuapp.com/assets/application-ac292d8e3f9c271670b08f58e5920cf3.js:14

Here is my Entity model in Ember which has a get_by_addr method that I use to access JSON data from my API.

    App.Entity = Ember.Object.extend({})


    App.Entity.reopenClass get_by_addr: (addr) ->
      $.getJSON("api/v1/entities?addr=" + addr ).then (response) ->
         entities = []
         a = App.Entity.create response
         a

This is my 'Entity' route

    App.EntitiesRoute = Ember.Route.extend
       model: (params)->
       App.Entity.get_by_addr(params.addr)

This is my applcation.js file in Rails

    //= require jquery
    //= require jquery_ujs
    //= require foundation
    //= require ember_application
    //= require_tree .

This is my production.rb file

    Rails.application.configure do

        # Disable Rails's static asset server (Apache or nginx will already do this).
        config.serve_static_assets = false

        config.assets.js_compressor = :uglifier
        # config.assets.css_compressor = :sass

        # Do not fallback to assets pipeline if a precompiled asset is missed.
        config.assets.compile = false

        # Generate digests for assets URLs.
        config.assets.digest = true

        # Version of your assets, change this if you want to expire all your assets.
        config.assets.version = '1.0'

        # Specifies the header that your server uses for sending files.
        # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
        # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx

        # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
        # config.assets.precompile += %w( search.js )
        config.ember.variant = :production
Vinay Raj
  • 11
  • 1
  • 4

1 Answers1

0

Is this the correct formatting for CoffeeScript? I think after your then you need to indent one more level.

App.Entity.reopenClass get_by_addr: (addr) ->
  $.getJSON("api/v1/entities?addr=" + addr ).then (response) ->
  entities = []
  a = App.Entity.create response

Second thing, there's a question of how the addr is being passed in: if it's a link-to from memory, params aren't automatically passed in beyond id.

Alex Lynham
  • 1,318
  • 2
  • 11
  • 29
  • sorry for the confusion but I have edited the question, I have the right coffee script indentation and thinks are working fine locally, I am calling it by using – Vinay Raj Jun 04 '14 at 10:30
  • Do you have any controller code? From what I remember I had a similar problem where a model was passing a non-valid or empty array forward to an `ArrayController` - wonder if that is the issue in some way. Also is `//= require ember_application` line 14 of your `application.js`? – Alex Lynham Jun 05 '14 at 07:59
  • I don't have any controller code but now I removed the 'Entity' model and accessing it directly from model like model:function(params) {return $.getJSON('/api/v1/entities.json?addr='+params.addr);} and now this is working fine ... I think there was some problem with my model or ember-data(because I am using ember-rails gem and that way have different copies of ember-data locally and on heroku) – Vinay Raj Jun 05 '14 at 10:31
  • That sounds like it could be to do with load paths potentially. I have to admit, I can't see why at a glance it might not be working from this code. Perhaps the changelog for Ember/Ember data versions will offer a clue. – Alex Lynham Jun 07 '14 at 14:36