シンプルな Ember-Rails アプリを取得しようとしていますが、すべて正常にレンダリングされているように見えますが、戻るボタンを押すと、レンダリングされたすべての要素が完全に削除されます。エラーなし。
私がこれまでに理解していることから、これは、Ember が「親」テンプレートが既にレンダリングされていると想定し、再レンダリングしないために発生します。私のアプリでは、最初に各投稿へのリンクを含む「投稿」のリストをレンダリングしています。各リンクは、レンダリングされた「投稿」ページを置き換えて、問題の投稿を開く必要があります。それは問題なく動作し、[戻る] ボタンをクリックすると、興味深いことが行われます。インデックス ページがレンダリングされ、アプリケーション テンプレート内のすべて (インデックスなどを含む) が完全に削除されます。
関連するコードのスニペットは次のとおりです。
まず、rails の application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Slimgur</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= stylesheet_link_tag 'bootstrap', media: 'all', 'data-turbolinks-track' => true %>
<%= stylesheet_link_tag 'bootstrap-theme', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
<div class='container'>
<div id="ember-app">
</div>
</div>
</body>
</html>
//This is the page that is rendered by rails.
<h1>Static#index</h1>
<p>Find me in app/views/static/index.html.erb</p>
/* Application.js file. After all require statements. */
App = Ember.Application.create({rootElement: '#ember-app'});
/* Router.js */
// --------------------------
App.Router.map(function() {
this.resource('posts');
this.resource('post', { path: 'posts/:id' });
})
/* Application.hbs. */
// --------------------------
<header>
<article>
<div class="logo">
<h1>
<a href="#">App</a>
</h1>
</div>
</article>
</header>
{{!-- This is intended to render all Ember Templates. --}}
<section id="main">
{{{outlet}}}
</section>
<footer>
<p> Testing Footer one two three </p>
</footer>
/* posts.hbs */
// --------------------------
<article id="posts">
<h1>Posts</h1>
<ul>
{{#each post in model}}
<li>{{#link-to 'post' post}}{{post.title}}{{/link-to}}</li>
{{/each}}
</ul>
</article>
{{outlet}}
/* post.hbs*/
// --------------------------
<h2>{{title}}</h2>
/* Ember Routes: */
// --------------------------
App.PostsRoute = Ember.Route.extend({
model: function(){
return this.store.find('post');
},
})
App.PostRoute = Ember.Route.extend({
model: function(params){
return this.store.find('post', params.id);
},
})
.hbs ファイルはハンドルバー テンプレートにコンパイルされると思います。