我正在使用 Jumpstartlab 博主教程。当我运行服务器并且想要打开文章时,我收到以下错误:
ArgumentError in Articles#show
Showing /home/darek/rails_projects/blogger/app/views/comments/_form.html.erb where line
#3 raised:
First argument in form cannot contain nil or be empty
Extracted source (around line #3):
1 <h3>Post a Comment</h3>
2
3 <% form_for [ @article, @comment ] do |f| %>
4 <p>
5 <%= f.label :author_name %><br/>
6 <%= f.text_field :author_name %>
_form.html.erb
<h3>Post a Comment</h3>
<% form_for [ @article, @comment ] do |f| %>
<p>
<%= f.label :author_name %><br/>
<%= f.text_field :author_name %>
</p>
<p>
<% f.label :body %><br/>
<% f.text_area :body %>
</p>
<p>
<%= f.submit 'Submit' %>
</p>
<% end %>
评论控制器.rb
class CommentsController < ApplicationController
def create
article_id = params[:comment].delete(:article_id)
@comment = Comment.new(params[:comment])
@comment.article_id = article_id
@comment.save
redirect_to article_path(@comment.article)
end
end
我尝试将代码与教程的 github 存储库进行比较,但没有帮助。本教程是为 Rails 3.x 准备的,我正在开发 4.0 有什么想法吗?