无法让基本的 emberjs 应用程序在 rails 平台上运行

Cannot get basic emberjs application to work on rails platform

我有一个 rails 应用程序,其中包含一个带索引操作的 StaticController:

class Private::StaticController < PrivateController

  def index

  end
end

routes.rb:

get 'static' => 'private/static#index'

我想在相应的视图中启动一个emberjs应用程序:

<%= javascript_include_tag 'ember_application' %>
<h1>Hello</h1>
<script type="text/x-handlebars">
  <div>{{outlet}}</div>
</script>

为此,我创建了一个基本的 emberJS 路由器:

PlatformUI.Router.map(function() {
  this.route('test', { path: '/test' });
});

PlatformUI.Router.reopen({
  rootURL: '/static/'
});

模板(在 app/assets/javascripts/templates/test.handlebars 中)包含:

<script type="text/x-handlebars" data-template-name="test">    
    <h2>Something</h2>
</script>

当运行应用程序时,页面上只显示'Hello'字样。 ember 检查器(chrome 插件)说 emberjs 已正确加载。路由有问题吗?我该如何调试它??

宝石文件:

gem 'ember-rails'
gem 'ember-source', '~> 1.9.1'

更新,我设法通过更改以下内容让转换记录器告诉我我在 /test 中:

PlatformUI.Router.map(function() {
  //this.route('index', { path: '/' });

  this.resource('test', { path: '/test' });

});

PlatformUI.Router.reopen({
  location: 'history',
  rootURL: '/static/'
});

虽然模板仍未加载。我在页面底部看到车把的脚本标签,它没有被使用。

不要在 test.handlebars 模板中包含脚本标签,此文件的内容应仅包含 handlebars 模板,即

<h2>Something</h2>

仅当将模板直接嵌入 html 时才需要脚本标签。

此外,rails 视图应包含如下内容:

<head>
    <!-- other standard head content -->
    <%= javascript_include_tag 'ember_application' %>
</head>
<body>
</body>

应用程序模板应在 application.handlebars 文件中,包含

<h1>Hello</h1>
<div>{{outlet}}</div>