Search code examples
ruby-on-railsruby-on-rails-3validationproduction-environment

Validations performed but fields not surrounded with field_with_errors div on Rails 3.2.0 only in production


I have a Publication model with validations on some fields, title for example.

I removed the error messages that I find annoying, and set up a nice CSS for when the input are surrounded in a field_with_error div so the user knows what field did not validate.

The thing is when I deploy to production the validations are still performed (ie. the user is sent back to the form) but the inputs are not surrounded with the error div.

I tried running the app locally in production mode and all I could learn is that it starts happening when I set config.cache_classes to true in my config/environments/production.rb file.

Also when I log @publication.errors in the controller the errors are present.

Any idea ?


Solution

  • On a rails 4.0.1 project I added an initializer:

    config/initializers/field_with_errors.rb
    

    with these lines

    ActionView::Base.class_eval do
      @@field_error_proc = Proc.new{ |html_tag, instance| "<div class=\"field_with_errors\">#{html_tag}</div>".html_safe }
    end