Unobtrusive Form Errors in Rails
Let's just add an error class to the LABEL and INPUT or TEXTAREA fields instead of injecting layers (<div class="error-fields">) into the form view.
config.action_view.field_error_proc = Proc.new do |html_tag, instance|
  class_attr_index = html_tag.index 'class="'
  if class_attr_index
    html_tag.insert class_attr_index + 7, 'error '
  else
    html_tag.insert html_tag.index('>'), ' class="error"'
  end
endWritten by Ryan Gasparini
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
 #Rails 
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#

 
 
 
 
