Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 21st, 2012  |  syntax: None  |  size: 1.13 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # This file goes in config/initializers
  2. require 'bootstrap_form_builder'
  3.  
  4. # Make this the default Form Builder. You can delete this if you don't want form_for to use
  5. # the bootstrap form builder by default
  6. ActionView::Base.default_form_builder = BootstrapFormBuilder::FormBuilder
  7.  
  8. # Add in our FormHelper methods, so you can use bootstrap_form_for.
  9. ActionView::Base.send :include, BootstrapFormBuilder::FormHelper
  10.  
  11. ### Only use one of these error handling methods ###
  12.  
  13. # Get rid of the rails error handling completely.
  14. ActionView::Base.field_error_proc = Proc.new do |html_tag, instance_tag|
  15.   "#{html_tag}".html_safe
  16. end
  17.  
  18. # Only remove the default rails error handling on input and label
  19. # Relies on the Nokogiri gem.
  20. # Credit to https://github.com/ripuk
  21. ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
  22.   html = %(<div class="field_with_errors">#{html_tag}</div>).html_safe
  23.   elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input"
  24.   elements.each do |e|
  25.     if e.node_name.eql? 'label'
  26.       html = %(#{e}).html_safe
  27.     elsif e.node_name.eql? 'input'
  28.       html = %(#{e}).html_safe
  29.     end
  30.   end
  31.   html
  32. end