私は次のような見方をしていますapp/views/posts/index.html.erb
:
<% @posts.each do |post| %>
<%= post.user %> is listening to <%= post.song %> by <%= post.artist %> from <%= post.album %>
<% end %>
そして対応するコントローラー:
class PostsController < ApplicationController
def index
@posts = Post.find(:all)
end
def show
@post = Post.find(params[:id])
end
def new
@post = Post.new
end
def create
@post = Post.new(params[:posts])
if @post.save
redirect_to action: "index"
else
@posts = Post.find(:all)
render action: 'new'
end
end
end
問題は、曲の属性が「The Sound of Settling」、アーティストの属性が「Death Cab for Cutie」、アルバムの属性が「Transatlanticism」のレコードを作成すると、インデックスビューをレンダリングしても何も表示されないことです。 。