-
-
Save dpmccabe/9144eb7dcf0d58154f33 to your computer and use it in GitHub Desktop.
add file as initializer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| | |
| html = %(<span class="has-error">#{html_tag}</span>).html_safe | |
| form_fields = %w(textarea input select) | |
| element = Nokogiri::HTML::DocumentFragment.parse(html_tag).css(['label', form_fields].join(', ')).first | |
| if element.node_name.eql?('label') | |
| html = %(<span class='has-error'>#{element}</span>).html_safe | |
| elsif form_fields.include?(element.node_name) | |
| html = %(<span class='has-error'>#{element}<span class='help-block'>#{[instance.error_message].join(', ')}</span></span>).html_safe | |
| end | |
| html | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment