我已经创建了一个 Rails 应用程序,并计划使用 ember 来实现其中的一部分。基本上我想要一条路线与 ember 应用程序链接,而其他页面是传统的 rails。但是,似乎默认情况下 ember 会在每个页面的 body 标记中插入一个 ember 模板,而我只希望在一个特定页面上发生这种情况。
例如,我希望路由“/ember”成为一个 ember 应用程序,其中呈现了 application.hbs。任何其他路由都由 rails 正常处理,ember 不会在页面中插入模板。
我怎样才能确定是这种情况?
最佳答案
我有一个类似的设置,只是我的 ember 应用程序附加到一个特定的元素,但这不会有太大的变化。诀窍是 deferReadiness,它告诉 ember 在你告诉它之前不要启动。因此,向应该具有 ember 应用程序的页面添加一些独特的东西,如果它不存在 deferReadiness,则将其从其他页面中排除。
window.App = App = Ember.Application.create({
rootElement: '#ember-container'
});
// AKA don't start the app cause aint nothing to hook up to
if($('#ember-container').length==0){
App.deferReadiness();
}
关于ruby-on-rails - Rails Ember 混合应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24129789/