Created
December 28, 2011 05:09
-
-
Save mgreenly/1526415 to your computer and use it in GitHub Desktop.
More on Twitter Bootsrap error handling in rails #1
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 BootStrapFormBuilder < ActionView::Helpers::FormBuilder | |
| # non-relevant code removed.... | |
| def text_field(*args, &block) | |
| input_wrapper(args.first) { | |
| super(*args, &block) | |
| } | |
| end | |
| def submit(value=nil, options={}) | |
| options[:class] = options[:class] || "btn primary" | |
| super(value, options) | |
| end | |
| private | |
| def input_wrapper(method) | |
| content_tag(:div, :class => "clearfix#{' error' unless @object.errors[method].blank?}") { | |
| concat(label method) | |
| concat(content_tag(:div, :class => "input#{' error' unless @object.errors[method].blank?}") { | |
| concat(yield) | |
| concat(content_tag(:span, :class => "help-inline"){ | |
| @object.errors[method].map{|e| "#{decorated_name(method)} #{e}." }.join(" ") | |
| }) | |
| }) | |
| } | |
| end | |
| # non-relevant code removed.... | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment