I cannot figure out why I'm getting this error, and exactly what it means.
First argument in form cannot contain nil or be empty(Line 3)
Add a new Post
<%= form_for @post do |f| %> //Error here
<p>
<%= f.label :title, 'Title' %><br/>
<%= f.text_field :title %><br/>
</p>
<p>
<%= f.label :content, 'Content'%><br/>
<%= f.text_area :content %><br/>
</p>
<p>
<%= f.submit "Add a New Post" %>
</p>
<% end %>
Controller:
class PostsController < ApplicationController
def index
@posts = Post.all
end
def show
@post = Post.find(params[:id])
end
def new
@post = Post.new
end
def create
@post = post.new(params[:post])
if @post.save
redirect_to posts_path, :notice => "Your post was saved"
else
render "new"
end
end
def edit
end
def update
end
def destroy
end
end
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…