为什么我在Ruby中收到NoMethodError?

马蒂亚斯·科德斯(Matthias Cordes)

我目前正在使用在导轨上使用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

结尾

m
  1. 您必须在“新”视图中呈现表单
  2. 您的数据库中必须有“标题”列

告诉我们'debug @recipe'打印的内容是什么,是否有'title'属性?

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么我在Ruby中收到NoMethodError?

来自分类Dev

为什么我会收到此错误 (NoMethodError)

来自分类Dev

为什么我得到 NoMethodError?

来自分类Dev

为什么我在DropDownListFor中的帖子中收到null异常?

来自分类Dev

Ruby:NoMethodError,但是为什么呢?

来自分类Dev

为什么我收到NumberFormatException

来自分类Dev

为什么我收到unsupportedSchemeError

来自分类Dev

为什么我收到 ArgumentOutOfRangeException

来自分类Dev

为什么我在跳过的队列中收到消息

来自分类Dev

为什么我在python中收到SQL语法错误

来自分类Dev

为什么我在角度2中收到“意外令牌<”错误?

来自分类Dev

为什么在我的save方法中收到此ValidationException?

来自分类Dev

为什么我在PHP中收到语法错误?

来自分类Dev

为什么我在TempData中收到NullReference异常

来自分类Dev

为什么我在终端中收到此“无法删除”行?

来自分类Dev

为什么我在Django中收到表单无效错误?

来自分类Dev

为什么我在PostListView中收到“ post”的关键错误

来自分类Dev

为什么我不能在componentDidMount中收到引用?(反应)

来自分类Dev

为什么我在Spark GraphX的Pregel中收到Typemismatch错误?

来自分类Dev

为什么我在终端中收到此“无法删除”行?

来自分类Dev

为什么我在Android中收到Null Pointer异常

来自分类Dev

为什么我在Vb.Net中收到这些错误?

来自分类Dev

为什么我在字典的实现中收到Python keyerror?

来自分类Dev

为什么我在简单的angularjs程序中收到此错误?

来自分类Dev

为什么我在objectForKey方法中收到警告?

来自分类Dev

为什么我在PL / SQL中收到此错误

来自分类Dev

为什么我不断从表单中收到电子邮件?

来自分类Dev

为什么我在URL帖子中收到通知“ Undefined index”

来自分类Dev

为什么我在 JTA EJB 的 @PostConstruct 方法中收到 TransactionRequiredException?

Related 相关文章

  1. 1

    为什么我在Ruby中收到NoMethodError?

  2. 2

    为什么我会收到此错误 (NoMethodError)

  3. 3

    为什么我得到 NoMethodError?

  4. 4

    为什么我在DropDownListFor中的帖子中收到null异常?

  5. 5

    Ruby:NoMethodError,但是为什么呢?

  6. 6

    为什么我收到NumberFormatException

  7. 7

    为什么我收到unsupportedSchemeError

  8. 8

    为什么我收到 ArgumentOutOfRangeException

  9. 9

    为什么我在跳过的队列中收到消息

  10. 10

    为什么我在python中收到SQL语法错误

  11. 11

    为什么我在角度2中收到“意外令牌<”错误?

  12. 12

    为什么在我的save方法中收到此ValidationException?

  13. 13

    为什么我在PHP中收到语法错误?

  14. 14

    为什么我在TempData中收到NullReference异常

  15. 15

    为什么我在终端中收到此“无法删除”行?

  16. 16

    为什么我在Django中收到表单无效错误?

  17. 17

    为什么我在PostListView中收到“ post”的关键错误

  18. 18

    为什么我不能在componentDidMount中收到引用?(反应)

  19. 19

    为什么我在Spark GraphX的Pregel中收到Typemismatch错误?

  20. 20

    为什么我在终端中收到此“无法删除”行?

  21. 21

    为什么我在Android中收到Null Pointer异常

  22. 22

    为什么我在Vb.Net中收到这些错误?

  23. 23

    为什么我在字典的实现中收到Python keyerror?

  24. 24

    为什么我在简单的angularjs程序中收到此错误?

  25. 25

    为什么我在objectForKey方法中收到警告?

  26. 26

    为什么我在PL / SQL中收到此错误

  27. 27

    为什么我不断从表单中收到电子邮件?

  28. 28

    为什么我在URL帖子中收到通知“ Undefined index”

  29. 29

    为什么我在 JTA EJB 的 @PostConstruct 方法中收到 TransactionRequiredException?

热门标签

归档