1

我正在自定义我的验证错误消息并且验证我的配方模型没有问题,但我无法验证我的嵌套模型成分。

class Recipe < ActiveRecord::Base
  has_many :ingredients

  accepts_nested_attributes_for :ingredients, :preperations

class Ingredient < ActiveRecord::Base
  belongs_to :recipe

这是我的 YAML 文件:

    en:
      errors:
        format: "%{message}"

         activerecord:
           errors:
             models: 
               recipe: 
                attributes:
                 dish_name:
                  blank: "Dont forget to give your Recipe a Dish Name"
                 country:
                  blank: "Dont forget to add the country name"
                 category:
                  blank: "Dont forget the category"
                 difficulty:
                  blank: "Dont forget to add the difficulty"
                 preperation_time:
                  blank: "Dont forget the preperation time"
              recipe/ingredients:
                attributes:
                 ingredient_name:
                 blank: "Cant have a recipe without ingredients can we?"

如何设置嵌套模型的验证?

任何帮助表示赞赏,谢谢。

编辑

我正在使用 rails 3.2.3 并且由于某种原因:在食谱/配料的末尾是白色而不是紫色,就像我的其余部分一样:

4

0 回答 0