0

我在rails-4应用程序上使用 Emberjs-1.0.0 和 Ember-data 1.0.0-beta-2 的最新金丝雀版本。当我在rails应用程序的emberjs应用程序中使用这个jsfiddle和确切的代码时,没有抛出错误,但是当我启动rails应用程序并尝试转到ember-app的索引页面时,它会抛出错误Uncaught TypeError : 对象 [对象对象] 没有方法 'applyPartial'

没有提到任何其他内容,因此很难调试或确定确切的问题。我已经删除了涡轮链接,所以这不是一个因素。

基于抛出的未捕获异常,它归结为 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

在此处输入图像描述

调用堆栈的屏幕截图,这里显示超类为 Store,其他时候显示为 unknownMixin 在此处输入图像描述

@Jeremy 这里是渲染后出现在我的页面中的完整标签列表。我通过查看页面源得到了这个我已经运行了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>
4

1 回答 1

2

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

//= require lib/development/ember

或者,为了更加确定,您可以完全删除 emberapplication.js并将最新的 canary ember 直接包含在您的布局中。

<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故意需要一次 ember

//= 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-railsvendor如果您只使用require emberin ,将找到 in 的版本application.js。您需要确保config.ember.variant在每个config/environments/*.rb文件中都进行了设置。例如,config/environments/development.rb您需要添加以下内容:

config.ember.variant = :development
于 2013-10-12T02:05:18.573 回答