【发布时间】:2013-09-01 20:49:33
【问题描述】:
我一直在努力寻找一个看似非常简单的问题的答案或解决方案。
我最近启动了 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>
模板/index.hbs
<h1> Hello World </h1>
所有必要的文件(ember、handlebars、jQuery)都被正确渲染,因为我在控制台中没有看到任何错误,它们在生成的 HTML 中。
我正在使用 gem handlebar_assets 编译 AssetsPipeline 的资产,并且正在正确生成模板。
为什么 ember 找不到模板?感谢您的帮助
更新这里是源代码,如果有人有兴趣看看它https://github.com/AppDojo/AppDojo-API/tree/ember-railsapi
解决方案
设置HandlebarsAssets::Config.ember = true 将模板的正确模板存储设置为Ember.TEMPLATES。我错过了 Handlebars 的 s...
【问题讨论】:
标签: javascript ruby-on-rails ember.js ruby-on-rails-4 rails-api