浏览器在 Locals#show 中返回了以下错误:
NilClass:Class 的未定义方法“model_name”
51: <%= form_for(@food) do |f| %>
52: <%= render 'shared/error_messages', object: f.object %>
53: <div class="field">
54: <%= f.label :nome %>
这是我的 locals_controller.rb (显示操作)
def show
@local = Local.find(params[:id])
@foods = @local.foods.paginate(page: params[:page])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @local }
end
结尾
这里 food_controller.rb (创建动作)
def create
@food = @local.foods.build(params[:food])
if @food.save
flash[:success] = "Food created!"
redirect_to '/locals'
else
flash[:error] = "Error on creating food"
render '/locals'
end
end
Food 模型和 Local 模型与 :has_many 和 belongs_to 相关
有什么问题?谢谢