Tuesday 21 October 2014

How to remove the field_with_errors div

In Rails 3, The field_with_errors div was messing up my column spacing.

I came up with the below solution:

# in application.html.erb

config.action_view.field_error_proc = Proc.new { |html_tag, instance| 
    html_tag.gsub('class="', 'class="with_error ').html_safe;
}

Now you can add the '.with_error' class to your CSS file and edit styling for individual input types.

/*In your application.css(or any other css file)*/
input.with_error {
    color: red;
}
label.with_error {
    color: red;
}

No comments:

Post a Comment