Skip to content

Instantly share code, notes, and snippets.

@mgreenly
Created December 28, 2011 05:09
Show Gist options
  • Select an option

  • Save mgreenly/1526415 to your computer and use it in GitHub Desktop.

Select an option

Save mgreenly/1526415 to your computer and use it in GitHub Desktop.
More on Twitter Bootsrap error handling in rails #1
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