我正在自定义验证错误消息,并且验证我的配方模型没有问题,但我无法验证我的嵌套模型成分。
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并且出于某种原因:食谱/配料的末端是白色而不是紫色,就像我的其他人一样: