1

我正在使用 Rails API 返回 JSON,然后Entity在 Ember 应用程序的模型中使用该 JSON。虽然这很好用localhost,但当我将应用程序部署到 Heroku 时它不起作用;它在控制台上显示此错误:

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

这是我Entity在 Ember 中的模型,它有一个get_by_addr用于从我的 API 访问 JSON 数据的方法。

    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

这是我的“实体”路线

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

这是我在 Rails 中的 applcation.js 文件

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

这是我的 production.rb 文件

    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
4

1 回答 1

0

这是 CoffeeScript 的正确格式吗?我认为在你之后then你需要缩进一个级别。

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

第二件事,有一个问题是如何addr传入的:如果它是link-to来自内存的,params 不会自动传入 Beyond id

于 2014-06-04T10:22:31.520 回答