上のオブジェクトとして印刷結果は私のposts_controller.rbがここルビー - ここに私のhtml
class PostsController < ApplicationController
def index
@posts = Post.all.order("created_at DESC")
end
def new
end
def create
@post = Post.new(post_params)
@post.save
redirect_to @post
end
def show
@post = Post.find(params[:id])
end
private
def post_params
params.require(:post).permit(:title, :body)
end
end
である私のindex.html.erb
<%= @posts.each do |post| %>
<div class="post_wrapper">
<h2 class="title"><%= link_to post.title, post %></h2>
<p class="date"><%= post.created_at.strftime("%B, %d, %Y") %></p>
</div>
<% end %>
はここでページがどのように見えるかですされています。 screenshot
なぜ[]行が表示されますか? どのように非表示/削除できますか?
使用 '<%@posts 。各|ポスト| %> ''なし ''の ' –
' show.html.erb'ファイルは 'index.html.erb'ではないのですか? – Uzbekjon