我正在尝试使用我的refineryCMS应用程序中的client_side_validations gem(https://github.com/bcardarella/client_side_validations)显示内联客户端验证错误。
当我选出一个无效字段时,它会被包含在span.fieldWithErrors标记中,正如预期的那样,所以我知道javascript验证正在运行。但是,即使重写了ActionView :: Base.field_error_proc,我也无法显示错误消息。
我觉得我的初始化程序后来被炼油厂(?)覆盖:
在config / initializers / client_side_validations.rb中:
# Uncomment the following block if you want each input field to have the validation messages attached.
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
unless html_tag =~ /^<label/
%{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe
else
%{<div class="field_with_errors">#{html_tag}</div>}.html_safe
end
end
我也尝试使用
中的内容设置config / application.rb中的field_error_procconfig.action_view.field_error_proc = Proc.new { |html_tag, instance| # etc... }
这些都不会对渲染无效字段产生任何影响。任何想法??
答案 0 :(得分:3)
结果是refineryCMS确实覆盖了field_error_proc:
https://github.com/refinery/refinerycms/issues/961
这对我有用:
# Uncomment the following block if you want each input field to have the validation messages attached.
Rails::Application.refinery.after_inclusion do
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
unless html_tag =~ /^<label/
%{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe
else
%{<div class="field_with_errors">#{html_tag}</div>}.html_safe
end
end
end