-
-
Save dustMason/5817510 to your computer and use it in GitHub Desktop.
Rails 3 ActionView override for Foundation 4 field error styles.
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
class Application < Rails::Application | |
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| | |
html = %(<div class="field_with_errors">#{html_tag}</div>).html_safe | |
# add nokogiri gem to Gemfile | |
elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input" | |
elements.each do |e| | |
if e.node_name.eql? 'label' | |
html = %(<div class="clearfix error">#{e}</div>).html_safe | |
elsif e.node_name.eql? 'input' | |
if instance.error_message.kind_of?(Array) | |
html = %(<div class="clearfix error">#{html_tag}<span class="help-inline"> #{instance.error_message.join(',')}</span></div>).html_safe | |
else | |
html = %(<div class="clearfix error">#{html_tag}<span class="help-inline"> #{instance.error_message}</span></div>).html_safe | |
end | |
end | |
end | |
html | |
end | |
end |
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
// Place all the styles related to the YourController controller here. | |
// They will automatically be included in application.css. | |
// You can use Sass (SCSS) here: http://sass-lang.com/ | |
form .clearfix:before, form .clearfix:after { | |
display: inline; | |
} |
This helped me out a bunch, thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that this wraps labels and inputs in their own
<div>
's. This is fine for my project, YMMV