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
Sometimes I wish more Rails features were opt-in - but then I'd spend a week customizing each project ><
I love you! <3
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 }
.
@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