Skip to content

Instantly share code, notes, and snippets.

@timm-oh
Created September 27, 2020 10:05
Show Gist options
  • Save timm-oh/febc9c7a2d12ce4bceb65554415702f3 to your computer and use it in GitHub Desktop.
Save timm-oh/febc9c7a2d12ce4bceb65554415702f3 to your computer and use it in GitHub Desktop.
Rails - Remove field_with_error

By default Rails wraps form errors in a div with the class field_with_errors.

There are 2 ways to disable this.

First way is in the application.rb environment file (doesn't make sense just to disable it on a specific environment?):

# config/application.rb

module ApplicationName
  class Application < Rails::Application
    config.action_view.field_error_proc = Proc.new do |html_tag, _instance|
      html_tag.html_safe
    end
  end
end

The second way is to disable it in an initializer:

# config/intializers/action_view_intializer.rb or whatever you want to call this initializer ¯\_(ツ)_/¯

ActionView::Base.field_error_proc = Proc.new do |html_tag, _instance|
  html_tag.html_safe
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment