gpt4 book ai didi

javascript - 基本的 Ember 模板不在 Rails 中呈现

转载 作者:行者123 更新时间:2023-11-29 19:46:04 27 4
gpt4 key购买 nike

请原谅我,因为我是 Ember(以及整个 Javascript 世界)的新手。我有一个使用 ember-rails gem 创建的 Rails 应用程序,我们称它为“warthog”

我的application.js文件如下:

//= require jquery
//= require jquery_ujs
//= require handlebars
//= require ember
//= require ember-data
//= require_self
//= require warthog
Warthog = Ember.Application.create();
//= require bootstrap

接下来是application.html.haml文件

%html
%head
%title Warthog
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "application"
= javascript_include_tag 'templates/application'

对于一些测试输出,我的 application.handlebars 文件中有一个字符串

This is a test

问题是 javascripts/templates/application.handlebars 没有被渲染。

请求完成后页面源码如下:

<html>
<head>
<title>Warthog</title>
<link href="/assets/application.css?body=1" media="all" rel="stylesheet" type="text/css" />
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/handlebars.js?body=1" type="text/javascript"></script>
<script src="/assets/ember.js?body=1" type="text/javascript"></script>
<script src="/assets/ember-data.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
<script src="/assets/store.js?body=1" type="text/javascript"></script>
<script src="/assets/controllers/application_controller.js?body=1" type="text/javascript"></script>
<script src="/assets/templates/application.js?body=1" type="text/javascript"></script>
<script src="/assets/routes/application_routes.js?body=1" type="text/javascript"></script>
<script src="/assets/router.js?body=1" type="text/javascript"></script>
<script src="/assets/warthog.js?body=1" type="text/javascript"></script>
<script src="/assets/templates/application.js?body=1" type="text/javascript"></script>
<script src="//www.google.com/jsapi" type="text/javascript"></script>
<script src="/assets/chartkick.js?body=1" type="text/javascript"></script>
<meta content="authenticity_token" name="csrf-param" />
<meta content="afE+P0e6I/KDeVpg/kLi8RvsPAAyYOwD6rE=" name="csrf-token" />
</head>
<body>
<div id='container'>

</div>
</body>
</html>

和控制台日志

DEBUG: ------------------------------- ember.js?body=1:394
DEBUG: Ember.VERSION : 1.0.0 ember.js?body=1:394
DEBUG: Handlebars.VERSION : 1.0.0 ember.js?body=1:394
DEBUG: jQuery.VERSION : 1.10.0 ember.js?body=1:394
DEBUG: ------------------------------- ember.js?body=1:394
Assertion failed: The view helper only takes a single argument ember.js?body=1:394
(anonymous function) ember.js?body=1:394
Ember.assert ember.js?body=1:53
(anonymous function) ember.js?body=1:25789
anonymous application.js?body=1:10
(anonymous function) handlebars.js?body=1:2214
Ember.View.Ember.CoreView.extend.render ember.js?body=1:20335
Ember.CoreView.Ember.Object.extend._renderToBuffer ember.js?body=1:19272
Ember.View.Ember.CoreView.extend._renderToBuffer ember.js?body=1:20915
superWrapper ember.js?body=1:1218
(anonymous function) ember.js?body=1:19253
Ember.Instrumentation.instrument ember.js?body=1:1662
Ember.CoreView.Ember.Object.extend.renderToBuffer ember.js?body=1:19252
Ember.View.Ember.CoreView.extend.createElement ember.js?body=1:20737
Ember.merge.insertElement ember.js?body=1:21686
Ember.View.Ember.CoreView.extend._insertElement ember.js?body=1:20665
DeferredActionQueues.flush ember.js?body=1:5459
Backburner.end ember.js?body=1:5545
Backburner.run ember.js?body=1:5584
Ember.run ember.js?body=1:5915
(anonymous function) ember.js?body=1:34656
fire jquery.js?body=1:3065
self.fireWith jquery.js?body=1:3177
jQuery.extend.ready jquery.js?body=1:434
completed jquery.js?body=1:105
Uncaught TypeError: Cannot read property '0' of undefined ember.js?body=1:25589
EmberHandlebars.ViewHelper.Ember.Object.create.helper ember.js?body=1:25589
(anonymous function) ember.js?body=1:25797
anonymous application.js?body=1:10
(anonymous function) handlebars.js?body=1:2214
Ember.View.Ember.CoreView.extend.render ember.js?body=1:20335
Ember.CoreView.Ember.Object.extend._renderToBuffer ember.js?body=1:19272
Ember.View.Ember.CoreView.extend._renderToBuffer ember.js?body=1:20915
superWrapper ember.js?body=1:1218
(anonymous function) ember.js?body=1:19253
Ember.Instrumentation.instrument ember.js?body=1:1662
Ember.CoreView.Ember.Object.extend.renderToBuffer ember.js?body=1:19252
Ember.View.Ember.CoreView.extend.createElement ember.js?body=1:20737
Ember.merge.insertElement ember.js?body=1:21686
Ember.View.Ember.CoreView.extend._insertElement ember.js?body=1:20665
DeferredActionQueues.flush ember.js?body=1:5459
Backburner.end ember.js?body=1:5545
Backburner.run ember.js?body=1:5584
Ember.run ember.js?body=1:5915
(anonymous function) ember.js?body=1:34656
fire jquery.js?body=1:3065
self.fireWith jquery.js?body=1:3177
jQuery.extend.ready jquery.js?body=1:434
completed jquery.js?body=1:105

解决方案:错误出在我的 Controller 和 Ember 中的路由文件中;我删除了那些,现在页面呈现

最佳答案

确保您的应用程序 Handlebars 模板以这种格式注入(inject)

<script type="text/x-handlebars" data-template-name="application">

</script>

<script type="text/x-handlebars" >

</script>

命名在 Ember 中非常重要,如果您的模板被注入(inject)不同的名称,例如:

<script type="text/x-handlebars" data-template-name="templates/application">

</script>

然后您需要一个应用程序 View ,该 View 指示使用与默认模板名称不同的模板名称。

Warthog.ApplicationView = Ember.View.extend({
templateName: 'templates/application'
})

关于javascript - 基本的 Ember 模板不在 Rails 中呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19602389/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com