我有以下观点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”的记录时,当我渲染索引视图时没有显示任何内容.