找不到“”;应用程序“;模板或视图.任何东西都不会被渲染Emberjs RailsAPI

Could not find "application" template or view. Nothing will be rendered Emberjs RailsAPI

本文关键字:Emberjs RailsAPI 任何东 应用程序 找不到 视图      更新时间:2023-09-26

我一直在试图找到一个答案或解决一个看起来很简单的问题。

我最近启动了RailsAPI应用程序。我决定玩EmberJS,并遵循最近在这里找到的教程

当我转到应用程序的索引页时,我看到的只是一个空白屏幕,我的模板不会呈现。由于某种原因,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

模板/应用程序.hbs

<div class='container'>
  <div class='content'>
    <div class='row'>
      <div class='span12'>
        <div class='page-header'></div>
          {{outlet}}
        </div>
      </div>
    </div>
  </div>
</div>

模板/索引.hbs

<h1> Hello World </h1>

所有必要的文件(ember、handlers、jQuery)都被正确呈现,因为我在控制台中没有看到任何错误,它们都在生成的HTML中。

我正在使用gem handlebar_assets编译AssetsPipeline的资产,并且模板正在正确生成。

为什么ember找不到模板?感谢的帮助

UPDATE如果有人感兴趣的话,下面是源代码https://github.com/AppDojo/AppDojo-API/tree/ember-railsapi

解决方案

设置HandlebarsAssets::Config.ember = true将模板的正确模板存储设置为Ember.TEMPLATES。我错过了Handlebars的一个s。。。

我想你的问题在于,handlerbus模板文件的扩展名应该是.hbs而不是.hb,试着将你的模板重命名为:

index.hbs
application.hbs
foo.hbs
...

希望能有所帮助。