我是 Rails 新手,正在阅读Ruby on Rails 入门教程。我在 5.7 Showing Posts 上遇到错误,上面写着'undefined method title' for nil:NilClass'
. 您能提供的任何帮助将不胜感激。
class PostsController < ApplicationController
def new
end
def create
@post = Post.new(params[:post].permit(:title, :text))
@post.save
redirect_to @post
end
private
def post_params
params.require(:post).permit(:title, :text)
end
def show
@post = Post.find(params[:id])
end
end
<p>
<strong>Title:</strong>
<%= @post.title %>
</p>
<p>
<strong>Text:</strong>
<%= @post.text %>
</p>