我有一个 Publication 模型,它对某些字段进行了验证,例如标题。
我删除了我觉得烦人的错误消息,并设置了一个漂亮的 CSS,以便当输入被包围在 field_with_error div 中时,用户可以知道哪个字段没有验证。
问题是,当我部署到生产环境时,验证仍在执行(即,用户被发送回表单)但输入没有被错误 div 包围。
我尝试在本地以生产模式运行该应用程序,我所能了解到的是,当我在我的 config/environments/production.rb 文件中将 config.cache_classes 设置为 true 时,它开始发生。
此外,当我在 Controller 中记录 @publication.errors 时,错误也出现了。
有什么想法吗?
最佳答案
在 rails 4.0.1 项目中,我添加了一个初始化程序:
config/initializers/field_with_errors.rb
用这些线
ActionView::Base.class_eval do
@@field_error_proc = Proc.new{ |html_tag, instance| "<div class=\"field_with_errors\">#{html_tag}</div>".html_safe }
end
关于ruby-on-rails - 仅在生产中执行了验证,但 Rails 3.2.0 上的字段未被 field_with_errors div 包围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11136120/