How can I stop Rails to change my code when validation isn't passed.
Every time rails wraps my field with
<div class='field_with_error'>...</div>
I can edit fields_with_error
class
.fields_with_error{ display: inline }
which works, but it is hacky
Its fine. Use the CSS thing instead of doing this.
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance_tag| "<span class='field_error'>#{html_tag}</span>" end
Which I feel is more hacky :)
I use this in environment.rb. Even more hacky ;-)
#
# Fix annoying <div class="fieldsWithError"> wrapping after validation
# http://dev.rubyonrails.org/ticket/3587
#
ActionView::Base.field_error_proc = Proc.new { |html_tag, instance|
msg = instance.error_message
if html_tag =~ /<(input|textarea|select)[>]+class=/
class_attribute = html_tag =~ /class=['"]/
html_tag.insert(class_attribute + 7, "error ")
elsif html_tag =~ /<(input|textarea|select)/
first_whitespace = html_tag =~ /\s/
html_tag[first_whitespace] = " class='error' "
end
html_tag
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With