我目前正在使用在导轨上使用ruby的食谱盒应用程序。当我想创建新食谱时说
未定义的方法“标题”
为了
= 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
结尾
告诉我们'debug @recipe'打印的内容是什么,是否有'title'属性?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句