Кажется, я не могу понять, почему мой ruby .each enumerable производит пустой div, если мой массив объектов пуст, или добавляет пустой div внизу, если в моем Переменная @posts.
Вот моя страница index.html.erb:
<div id="post_feed">
<%if @posts.any?%>
<%@posts.each do |p|%>
<div class="post_text_box">
<%=p.body%>
</div>
<%end%>
<%end%>
</div>
Пост-контролер:
def index
@posts = current_user.posts
@new_post = current_user.posts.new
end
CSS:
#post_feed{
margin-right:auto;
margin-left:auto;
width:400px;
}
.post_text_box{
padding:10px;
margin:10px;
background-color:#FFFFFF;
}
рельсы консоли показывает 1 шт.
irb(main):014:0> Post.count
(1.3ms) SELECT COUNT(*) FROM "posts"
=> 1