[英]error messages displaying in wrong order when using accepts_nested_attributes_for
I guess I am running into a lot of issues related to error messages, another one. 我想我遇到了许多与错误消息有关的问题,另一个是。
I have the following in my model 我的模型中有以下内容
class Recipe < ActiveRecord::Base
has_many :recipe_ingredients
validates_presence_of :title, :message => "Recipe title cannot be left blank"
validates_presence_of :servingsize, :message => "Please enter a serving size for the recipe"
accepts_nested_attributes_for :recipe_ingredients
end
In "RecipeIngredient" model I have this 在“ RecipeIngredient”模型中,我有这个
class RecipeIngredient < ActiveRecord::Base
belongs_to :recipe
validates_presence_of :ingredient_id, :serving_size_id, :quantity
end
Now when I see the error messages I see error messages for the recipe ingredient model first and not for the recipe model. 现在,当我看到错误消息时,首先看到的是配方配料模型而不是配方模型的错误消息。 How can I display error messages for the recipe model first?
如何首先显示配方模型的错误消息?
I am running ruby v1.8.7 and rails v2.3.5 我正在运行ruby v1.8.7和rails v2.3.5
Thanks. 谢谢。
How are you displaying the error messages, with error_messages_for? 您如何使用error_messages_for显示错误消息? I think errors are stored in a hash in which case it has no guaranteed order.
我认为错误存储在哈希中,在这种情况下它没有保证的顺序。 You could roll your own helper, or how about display the errors inline:
您可以滚动自己的帮助器,或内联显示错误:
<%= error_message_on @recipe, :title %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.