Ruby on rails 是否在我的实际post对象之后返回post对象的活动记录数组?
我正在我的用户#show视图中显示用户的所有帖子,除了在实际帖子之后返回一个用户所有帖子的数组外,它工作正常。以下是用户控制器的显示操作:Ruby on rails 是否在我的实际post对象之后返回post对象的活动记录数组?,ruby-on-rails,ruby,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 4,我正在我的用户#show视图中显示用户的所有帖子,除了在实际帖子之后返回一个用户所有帖子的数组外,它工作正常。以下是用户控制器的显示操作: def show @user = User.find(params[:id]) @posts = @user.posts.all end users/show.html.erb <div class="profile"> <%= image_tag @user.image.url(:thumb) %> <h4
def show
@user = User.find(params[:id])
@posts = @user.posts.all
end
users/show.html.erb
<div class="profile">
<%= image_tag @user.image.url(:thumb) %>
<h4><%= @user.name %></h4>
</div>
<div class="userposts">
<%= @posts.each do |post| %>
<h8><%= link_to post.title, post_path(post) %></h8>
<p><%= truncate(post.content, length: 250, omission: '... (continued)') %></p>
<% end %>
</div>
将此
更改为此
在erb
Post id: 1, title: "post", content: "content", created_at: "2014-12-02 14:07:43", updated_at: "2014-12-02 14:07:43", user_id: 1 Post id: 2, title: "Another Post", content: "more content", created_at: "2014-12-02 14:29:26", updated_at: "2014-12-02 14:29:26", user_id: 1