Ruby on rails 厨师中的命名错误#显示。。。未定义的方法`name';零级:零级

Ruby on rails 厨师中的命名错误#显示。。。未定义的方法`name';零级:零级,ruby-on-rails,Ruby On Rails,大家好,我正在关注《Rails入门指南》 我很难让show.html.erb正常工作 我与本教程的分歧仅限于本教程使用的范围: rails生成模型文章标题:string text:text 但我用过 rails生成模型厨师姓名:string电子邮件:string 问题是my show.html.erb: <p> <strong>Name:</strong> <%= @chef.name %> </p> <p>

大家好,我正在关注《Rails入门指南》 我很难让show.html.erb正常工作

我与本教程的分歧仅限于本教程使用的范围:

rails生成模型文章标题:string text:text

但我用过

rails生成模型厨师姓名:string电子邮件:string

问题是my show.html.erb:

<p>
  <strong>Name:</strong>
  <%= @chef.name %>
</p>

<p>
  <strong>Email:</strong>
  <%= @chef.email %>
</p>

名称:

电子邮件:

提出了一个“NoMethodError in Chefs#show”…“nil:NilClass的未定义方法'name'

请问我做错了什么

这是我的车夫控制器:

class ChefsController < ApplicationController

def new
end

def create
    @chef = Chef.new(chef_params)

    @chef.save
    redirect_to @chef
end

private
  def chef_params
    params.require(:chef).permit(:name, :email)
  end

def show
    @chef = Chef.find(params[:id])
end


end
class ChefsController
show
方法移到
private

class ChefsController < ApplicationController

def new
end

def create
    @chef = Chef.new(chef_params)

    @chef.save
    redirect_to @chef
end

def show
    @chef = Chef.find(params[:id])
end

private
  def chef_params
    params.require(:chef).permit(:name, :email)
  end

end
class ChefsController

private
下定义的任何
method
都被视为
private method

您可以发布控制器的show方法吗?