Ruby on rails 厨师中的命名错误#显示。。。未定义的方法`name';零级:零级
大家好,我正在关注《Rails入门指南》 我很难让show.html.erb正常工作 我与本教程的分歧仅限于本教程使用的范围: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生成模型文章标题: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方法吗?