Remove Rails field_with_errors wrapper
Are your form styles screwed up after validation? Are you sick of dealing with the standard Rails field_with_errors wrappers?
GET RID OF THEM!!!!11!
Here's a simple trick to do away with those pesky wrappers once and for all. Just add this block to your config/environment.rb file.
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
html_tag.html_safe
end
Problem solved.
Written by Anthony Smith
Related protips
6 Responses
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/53200/Transparent-Large.png)
Sometimes I wish more Rails features were opt-in - but then I'd spend a week customizing each project ><
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/93208/68b922c33b2876d58ae6672a2600c53e.jpg)
I love you! <3
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/10300/dd2d775dea75b381edb1bbf0600a0907.jpeg)
There's no reason to do this. If you don't want field_with_errors
styled specially, just ignore it. If the extra <div>
elements break your layout, just put something like the following in your CSS: .field_with_errors { display: inline }
.
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/144856/rails-5-upgrade.jpg)
@marnen when there is no indication of the div in the code, I bet the given solution is the best you can go with
easy and efficient. Thanks !
Thanks a lot