我正在尝试获取一个简单的Ember-Rails应用程序,一切似乎都很好,但是后退按钮完全删除了所有渲染的元素。没有错误。
据我目前所知,发生这种情况是因为 Ember 希望"父"模板已经呈现并且不会重新渲染它。在我的应用程序中,我首先呈现一个"帖子"列表,其中包含指向每个帖子的链接。每个链接都应该打开有问题的帖子,替换呈现的"帖子"页面。它做得很好,然后当我单击后退按钮时,它会做一些有趣的事情:它呈现索引页,然后完全删除应用程序模板中的所有内容(包括索引等)。
以下是相关的代码片段:
一、导轨应用.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文件编译为车把模板。
好吧,最终,我最终删除了涡轮链接。我仍然有点不确定这样做,但它似乎还没有以任何方式妨碍我的申请。
为此,您必须删除 turbolinks gem、应用程序中的"需要 turbolinks"行.js以及 application.html.erb 中的 turbolink 标签。
我交叉手指,希望这不会搞砸任何我没有见过的东西。