大佬教程收集整理的这篇文章主要介绍了ruby-on-rails – Rails验证和’fieldWithErrors’包装选择标记,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我确实在该字段的error_messages_for和error_message_on方法中得到错误.
Ps.我已经改变了一点ActionView :: Base.field_error_proc以获得span标签而不是div,但这不是问题.
ActionView::Base.field_error_proc = Proc.new { |html_tag,instance| #if I puts html_tag here I only get the <input> tags "<span class=\"fieldWithErrors\">#{html_tag}</span>" }@H_489_8@
我通过改变来解决这个恼人的问题
object.errors.on(@method_Name)
至
object.errors.on(@method_Name) || object.errors.on(@method_name.gsub(/_id$/,''))
这是差异(针对Rails 2.3.4):
diff --git a/vendor/rails/actionpack/lib/action_view/Helpers/active_record_Helper.rb b/vendor/rails/actionpack/lib/action_view/Helpers/active_record_Helper.rb index 541899e..5d5b27e 100644 --- a/vendor/rails/actionpack/lib/action_view/Helpers/active_record_Helper.rb +++ b/vendor/rails/actionpack/lib/action_view/Helpers/active_record_Helper.rb @@ -247,7 +247,7 @@ module ActionView alias_method :tag_without_error_wrapping,:tag def tag(name,options) if object.respond_to?(:errors) && object.errors.respond_to?(:on) - error_wrapping(tag_without_error_wrapping(name,options),object.errors.on(@method_Name)) + error_wrapping(tag_without_error_wrapping(name,object.errors.on(@method_Name) || object.errors.on(@method_name.gsub(/_id$/,''))) else tag_without_error_wrapping(name,options) end @@ -256,7 +256,7 @@ module ActionView alias_method :content_tag_without_error_wrapping,:content_tag def content_tag(name,value,options) if object.respond_to?(:errors) && object.errors.respond_to?(:on) - error_wrapping(content_tag_without_error_wrapping(name,object.errors.on(@method_Name)) + error_wrapping(content_tag_without_error_wrapping(name,''))) else content_tag_without_error_wrapping(name,options) end@H_489_8@ @H_489_8@
以上是大佬教程为你收集整理的ruby-on-rails – Rails验证和’fieldWithErrors’包装选择标记全部内容,希望文章能够帮你解决ruby-on-rails – Rails验证和’fieldWithErrors’包装选择标记所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。