我很抱歉我的英语不好。我只是试图描述我的问题。 :) 我有一个应用程序布局,有一个产量显示职位在体内。我有另一个yield:footerpost3用于在页脚上显示最近帖子的标题。Ruby on Rails 3:玩意
当我在localhost:3000时,yield:footerpost3正确显示最近的标题。但是当我点击一个帖子链接,这是url是localhost:3000/posts/3,yield:footerpost3什么都不显示。
这里是我的代码: 应用程序/视图/布局/ application.html.erb
<!-- begin footer comment widget -->
<div class="footer_list widget_recent_comments">
<div class="title"><h5>Artikel Terkini</h5></div>
<%= yield :footerpost3 %>
</div>
<!-- end footer comment widget -->
应用程序/视图/存储/ index.html.erb
<% content_for :footerpost3 do %>
<% @postsMain.each do |dopostAll| %>
<div class="entry">
<ul>
<li class="recentcomments"><%= link_to dopostAll.title, dopostAll %></li>
</ul>
</div>
<% end %>
<% end %>
我希望我的问题很容易理解.. :)
为
footerpost3
的内容,所以我必须插入一个 <%=渲染:文件=>在每一个“布局/应用程序”%> 代码中的另一个看法? 有没有简单的方法?像应用程序帮手?老实说,我不明白应用帮手:) – mamatozay不是每个视图。这个例子显示了你如何使用布局来做到这一点。您的所有帖子视图(索引,显示,新建,编辑)将自动在此布局中呈现。所以你只能把它放在一个地方。诀窍是你必须确保所有在这个布局内渲染的视图都定义了@ postsMain,否则它们会被破坏。 – numbers1311407
感谢您的帮助。 我知道明白了。 – mamatozay