【发布时间】:2026-01-26 01:25:01
【问题描述】:
我正在尝试用 Ruby on rails 创建一个博客,我想在我的视图中显示 posts 表。就像我的美貌一样简单,有些事情会失败。在遍历整个表并将记录呈现到我的视图之后,它还会将一个包含完整表的数组呈现到我的视图中。
创建这个视图的代码是这样的:
<%= @posts.each do |post| %>
<div class="post_wrapper">
<h1 class="title">
<%= post.title %>
</h1>
<p class="date">
Submitted <%= time_ago_in_words(post.created_at) %> Ago
</p>
<p class="body">
<%= post.body %>
</p>
</div>
<p style="color:red; font-size:1.5em;">the array is added after the div</p>
<%end%>
<p style="color:red; font-size:1.5em;">but still inside the loop</p>
<br />
<%= link_to "New post", new_post_path %>
【问题讨论】:
标签: ruby-on-rails arrays ruby view