I have the following view in app/views/posts/index.html.erb:
<% @posts.each do |post| %>
<%= post.user %> is listening to <%= post.song %> by <%= post.artist %> from <%= post.album %>
<% end %>
And the corresponding controller:
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 problem is, when I create a record with the song attribute being “The Sound of Settling”, the artist attribute being “Death Cab for Cutie”, and the album atrribute being “Transatlanticism”, nothing shows up when I render the index view.
As @house9 and @bdares said, I had
:postsin mycreateaction when it should have been:post.