【发布时间】:2015-01-30 18:07:02
【问题描述】:
我有一个包含带有索引操作的 StaticController 的 Rails 应用程序:
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/'
});
模板仍然没有加载。我在页面底部看到了车把的脚本标签,它没有被使用。
【问题讨论】:
-
您用来访问 Ember 应用程序的 url 是什么?要调试,请尝试启用转换记录(请参阅here);如果您不在 './test' 路线中,则不会有任何内容呈现到 {{outlet}}...
-
@jesenko 我在 /static/#/test
-
转换日志的输出怎么样?
-
@jesenko
Attempting URL transition to /。我现在在 /static/test 中。我已经尝试过 /static/test 和 /static/#/test -
@jesenko 我发布了更新。