我目前正在研究配方盒应用程序,在轨道上使用ruby。当我想创建一个新配方它说
未定义的方法`title'
的
= f.input :title, input_html: { class: 'form-control' }
这是我的 form.html.haml
= simple_form_for @recipe, html: { multipart: true } do |f|
- if @recipe.errors.any?
#errors
%p
= @recipe.errors.count
Prevented this recipe from saving
%ul
- @recipe.errors.full_messages.each do |msg|
%li= msg
.panel-body
= f.input :title, input_html: { class: 'form-control' }
= f.input :description, input_html: { class: 'form-control' }
= f.button :submit, class: "btn btn-primary"
这是我的 recipes_controller.rb
class RecipesController < ApplicationController
before_action :find_recipe, only: [:show, :edit, :update, :destroy]
def index
end
def show
end
def new
@recipe = Recipe.new
end
def create
@recipe = Recipe.new(recipe_params)
if @recipe.save
redirect_to @recipe, notice: "Toll! Neues Rezept erfolgreich erstellt."
else
render 'new'
end
end
private
def recipe_params
params.require(:recipe).permit(:title, :description)
end
def find_recipe
@recipe = Recipe.find(params[:id])
end
端
答案 0 :(得分:1)
向我们展示&#39; debug @ recipe&#39;打印,是否有标题&#39;属性?