我一直在努力寻找一个看似非常简单的问题的答案或解决方案。
我最近启动了 RailsAPI 应用程序。我决定尝试使用 EmberJS 并按照最近找到的教程 here 进行操作
当我转到我的应用程序的索引页面时,我看到的只是一个空白屏幕,我的模板不会呈现。 Ember 似乎出于某种原因无法找到我的模板。
这是我在控制台中看到的内容:
DEBUG: ------------------------------- ember-1.0.0.js?body=1:394
DEBUG: Ember.VERSION : 1.0.0 ember-1.0.0.js?body=1:394
DEBUG: Handlebars.VERSION : 1.0.0 ember-1.0.0.js?body=1:394
DEBUG: jQuery.VERSION : 1.9.1 ember-1.0.0.js?body=1:394
DEBUG: ------------------------------- ember-1.0.0.js?body=1:394
generated -> route:application Object {fullName: "route:application"} ember-1.0.0.js?body=1:394
generated -> route:index Object {fullName: "route:index"} ember-1.0.0.js?body=1:394
generated -> controller:application Object {fullName: "controller:application"} ember-1.0.0.js?body=1:394
Could not find "application" template or view. Nothing will be rendered Object {fullName: "template:application"} ember-1.0.0.js?body=1:394
generated -> controller:index Object {fullName: "controller:index"} ember-1.0.0.js?body=1:394
Could not find "index" template or view. Nothing will be rendered Object {fullName: "template:index"} ember-1.0.0.js?body=1:394
Transitioned into 'index' ember-1.0.0.js?body=1:394
=> Ember.TEMPLATES
# Object {}
如您所见,Ember.TEMPLATES 是空的。我当前的应用程序结构如下所示
Dojo
- app
- assets
- javascripts
- templates
- application.hbs
- index.hbs
- application.js.coffee
- router.js.coffee
- controllers
等等,我会根据需要更新。它几乎是一个基本的 Rails 应用程序。
这是我的相关文件的样子:
application.js.coffee
#= require jquery-1.9.1
#= require handlebars-1.0.0
#= require ember-1.0.0
#= require ember-data
#= require_self
#= require router
#= require_tree ./models
#= require_tree ./controllers
#= require_tree ./views
#= require_tree ./templates
#= require_tree ./routes
window.AppDojoApi = Ember.Application.create
LOG_TRANSITIONS: true
LOG_BINDINGS: true
LOG_ACTIVE_GENERATION: true
LOG_VIEW_LOOKUPS: true
console.log Ember.TEMPLATES
templates/application.hbs
<div class='container'>
<div class='content'>
<div class='row'>
<div class='span12'>
<div class='page-header'></div>
{{outlet}}
</div>
</div>
</div>
</div>
</div>
templates/index.hbs
<h1> Hello World </h1>
所有必要的文件(ember、handlebars、jQuery)都被正确呈现,因为我在控制台中没有看到任何错误,它们在生成的 HTML 中。
我正在使用 gem handlebar_assets
为 AssetsPipeline
编译 Assets ,并且正在正确生成模板。
为什么 ember 找不到模板?感谢您的帮助
更新如果有人有兴趣看一下,这是源代码https://github.com/AppDojo/AppDojo-API/tree/ember-railsapi
解决方案
设置 HandlebarsAssets::Config.ember = true
将模板的正确模板存储设置为 Ember.TEMPLATES
。我从 Handlebars 中遗漏了一个 s
...
最佳答案
我猜你的问题在于 handlebars 模板文件扩展名应该是 .hbs
而不是 .hb
,尝试将你的模板重命名为:
index.hbs
application.hbs
foo.hbs
...
希望对您有所帮助。
关于javascript - 找不到 "application"模板或 View 。什么都不会呈现 Ember Js Rails API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18562793/