Что на земле?
В сообщениях / _post_brief.html.haml:
- title link_to "#{post_brief.title} by #{post_brief.user.full_name}", post_brief
- content_for :info do
- if post_brief.tags.count > 0
Tags: #{post_brief.tags.collect {|t| t.name}.join(", ")}
- content_for :post_body do
=post_brief.message
В posts / _post_wrapper.html.haml:
.post
.right
%h2= yield :title
%p.post-info= yield :info
= yield :post_body
.left
%p.dateinfo
JAN
%span 31
.post-meta
%h4 Playlist Info
%ul
%li.user
%a{:href => "#"} Erwin
%li.time
%a{:href => "#"} 12:30 PM
%li.comment
%a{:href => "#"} 2 Comments
%li.permalink
%a{:href => "#"} Permalink
В posts / index.html.haml:
- title "Posts"
- content_for :info do
Lots of posts here!
- content_for :main_content do
-# @posts.each do |post|
= render :partial => "post_brief", :layout => "post_wrapper", :collection => @posts
= link_to 'New post', new_post_path
В раскладках / application.html.erb (только соответствующая часть)
<div id="main">
<%= yield(:main_content) or yield %>
</div>
Результатом является следующий HTML:
<div class='post'>
<div class='right'>
<h2><a href="/posts/545688642">Love Potion No. 23 by John Smith</a></h2>
<p class='post-info'>Lots of posts here!</p>
The is such a flawed product!
This potion, Love Potion No. 7, is defective!
This potion, Love Potion No. 25, is defective!
This potion, Love Potion No. 13, is defective!
This potion, Love Potion No. 17, is defective!
This potion, Love Potion No. 3, is defective!
This potion, Love Potion No. 21, is defective!
This potion, Love Potion No. 4, is defective!
This potion, Love Potion No. 10, is defective!
This potion, Love Potion No. 14, is defective!
This potion, Love Potion No. 22, is defective!
This potion, Love Potion No. 8, is defective!
This potion, Love Potion No. 18, is defective!
This potion, Love Potion No. 1, is defective!
This potion, Love Potion No. 23, is defective!
</div>
<div class='left'>
<p class='dateinfo'>
JAN
<span>31</span>
</p>
<div class='post-meta'>
<h4>Playlist Info</h4>
<ul>
<li class='user'>
<a href='#'>Erwin</a>
</li>
<li class='time'>
<a href='#'>12:30 PM</a>
</li>
<li class='comment'>
<a href='#'>2 Comments</a>
</li>
<li class='permalink'>
<a href='#'>Permalink</a>
</li>
</ul>
</div>
</div>
</div>
<div class='post'>
<div class='right'>
<h2><a href="/posts/545688642">Love Potion No. 23 by John Smith</a></h2>
<p class='post-info'>Lots of posts here!</p>
The is such a flawed product!
This potion, Love Potion No. 7, is defective!
This potion, Love Potion No. 25, is defective!
This potion, Love Potion No. 13, is defective!
This potion, Love Potion No. 17, is defective!
This potion, Love Potion No. 3, is defective!
This potion, Love Potion No. 21, is defective!
This potion, Love Potion No. 4, is defective!
This potion, Love Potion No. 10, is defective!
This potion, Love Potion No. 14, is defective!
This potion, Love Potion No. 22, is defective!
This potion, Love Potion No. 8, is defective!
This potion, Love Potion No. 18, is defective!
This potion, Love Potion No. 1, is defective!
This potion, Love Potion No. 23, is defective!
</div>
<div class='left'>
<p class='dateinfo'>
JAN
<span>31</span>
</p>
<div class='post-meta'>
<h4>Playlist Info</h4>
<ul>
<li class='user'>
<a href='#'>Erwin</a>
</li>
<li class='time'>
<a href='#'>12:30 PM</a>
</li>
<li class='comment'>
<a href='#'>2 Comments</a>
</li>
<li class='permalink'>
<a href='#'>Permalink</a>
</li>
</ul>
</div>
</div>
</div>
и так далее. (В @post есть 15 элементов; каждый из них должен иметь однострочное описание, но, как вы видите, все 15 описаний печатаются для каждого элемента.)
Я также попытался изменить index.html.haml на
- content_for :main_content do
- @posts.each do |post|
= render :partial => "post_brief", :layout => "post_wrapper", :locals => {:post => post}
но это вызвало еще более безумное поведение - у первой записи было одно описание, у второй - два и т. Д.
Что случилось?