Emberjs-1.0.0 app - 未捕获TypeError:对象[object Object]没有方法'applyPartial'

时间:2013-09-19 10:25:40

标签: ruby-on-rails ember.js ruby-on-rails-4 ember-data ember-router

我在 rails-4 应用上使用最新的Emberjs-1.0.0和Ember-data 1.0.0-beta-2的canary版本。当我使用带有来自rails应用程序的emberjs应用程序中的确切代码的 jsfiddle 时,不会抛出任何错误,但是当我启动rails应用程序并尝试转到该应用程序的索引页面时ember-app,它会抛出错误未捕获TypeError:对象[object Object]没有方法'applyPartial'

没有提到任何其他内容使得调试或确定问题变得困难。我已经删除了turbo-links,所以这不是一个因素。

基于未捕获的异常抛出,它归结为emberjs中的这一行 https://github.com/emberjs/ember.js/blob/8624e8513a8db0294856cd3f559127dd7a7820b3/packages/ember-runtime/lib/system/core_object.js#L147

Class.PrototypeMixin.applyPartial(Class.prototype);

此屏幕截图基于未在rails-4应用中加载的emberjs-app

enter image description here

callstack的屏幕截图,这里显示超类为Store,有时显示unknownMixin enter image description here

@Jeremy here是渲染后在我的页面中显示的完整标签列表。我通过查看页面源得到了这个 rake tmp:clear rake assets:clean ,但问题仍然存在

   <script src="/assets/jquery.js?body=1"></script>
   <script src="/assets/jquery_ujs.js?body=1"></script>
   <script src="/assets/handlebars.js?body=1"></script>
   <script src="/assets/ember.js?body=1"></script>
   <script src="/assets/ember-data.js?body=1"></script>
   <script src="/assets/application.js?body=1"></script>
   <script src="/assets/store.js?body=1"></script>
   <script src="/assets/models/users.js?body=1"></script>
   <script src="/assets/controllers/application_controller.js?body=1"></script>
   <script src="/assets/controllers/login_controller.js?body=1"></script>
   <script src="/assets/controllers/signup_controller.js?body=1"></script>
   <script src="/assets/controllers/user_controller.js?body=1"></script>
   <script src="/assets/controllers/user_edit_controller.js?body=1"></script>
   <script src="/assets/controllers/users_controller.js?body=1"></script>
   <script src="/assets/templates/application.js?body=1"></script>
   <script src="/assets/templates/index.js?body=1"></script>
   <script src="/assets/templates/login.js?body=1"></script>
   <script src="/assets/templates/signup.js?body=1"></script>
   <script src="/assets/templates/user.js?body=1"></script>
   <script src="/assets/templates/user/edit.js?body=1"></script>
   <script src="/assets/templates/user/index.js?body=1"></script>
   <script src="/assets/templates/users.js?body=1"></script>
   <script src="/assets/templates/users/index.js?body=1"></script>
   <script src="/assets/router.js?body=1"></script>
   <script src="/assets/routes/application_route.js?body=1"></script>
   <script src="/assets/routes/authenticated_route.js?body=1"></script>
   <script src="/assets/routes/login_route.js?body=1"></script>
   <script src="/assets/routes/signup_route.js?body=1"></script>
   <script src="/assets/routes/user/edit_route.js?body=1"></script>
   <script src="/assets/routes/user/index_route.js?body=1"></script>
   <script src="/assets/routes/user_route.js?body=1"></script>
   <script src="/assets/routes/users/index_route.js?body=1"></script>
   <script src="/assets/routes/users_route.js?body=1"></script>
   <script src="/assets/app.js?body=1"></script>
   <script src="/assets/lib/development/ember-data.js?body=1"></script>
  <script src="/assets/lib/development/ember.js?body=1"></script>
  <script src="/assets/lib/production/ember-data.js?body=1"></script>
  <script src="/assets/lib/production/ember.js?body=1"></script>
  <script src="/assets/note_books.js?body=1"></script>
  <script src="/assets/notes.js?body=1"></script>

1 个答案:

答案 0 :(得分:2)

由于ember-rails中有Gemfile,您可能会获得它提供的Ember版本,而不是app/assets/javascripts/lib/development中的版本。您可以在浏览器中加载/assets/ember.js进行验证。如果您想确保获得自定义版本,请在application.js

中使用此版本
//= require lib/development/ember

或者更确切地说,您可以完全删除application.js中的余烬,并将最新的金丝雀余烬直接包含在您的布局中。

<script type='text/javascript' src="http://builds.emberjs.com/canary/ember.js"></script>

[更新]:好的,问题是你多次包含ember.js(可能还有多个版本)。当你第一次发布脚本标签的位列表时,我错过了它,但如果仔细观察,你会看到Ember和Ember Data被包含在顶部(脚本的第4和第5行),然后它们就是每个都包括两个底部的更多次。

...
<script src="/assets/ember.js?body=1"></script>
<script src="/assets/ember-data.js?body=1"></script>
...
<script src="/assets/lib/development/ember-data.js?body=1"></script>
<script src="/assets/lib/development/ember.js?body=1"></script>
<script src="/assets/lib/production/ember-data.js?body=1"></script>
<script src="/assets/lib/production/ember.js?body=1"></script>
...

我的猜测是application.js需要一次性使用

//= require ember

然后用require_tree

再次拾起它
//= require_tree .

通常,您希望将外部库(您未亲自维护的代码)存储在应用的vendor目录中。这将允许仍然使用require_tree来获取一次性包含的所有自己的javascript。在我使用ember-rails的项目中,我的结构如下所示:

app
  assets
    javascripts
      # All my own stuff goes here
vendor
  assets
    ember
      development
        ember.js
        ember-data.js
      production
        ember.js
        ember-data.js
如果您在ember-rails中使用vendor

require ember会在application.js中找到这些版本。您需要确保在每个config.ember.variant文件中设置config/environments/*.rb。例如,在config/environments/development.rb中,您需要添加以下内容:

config.ember.variant = :development