Skip to content

Instantly share code, notes, and snippets.

@mgreenly
Created December 27, 2011 03:03
Show Gist options
  • Save mgreenly/1522609 to your computer and use it in GitHub Desktop.
Save mgreenly/1522609 to your computer and use it in GitHub Desktop.
rails form formatting for twitter bootstrap #4
# ./app/helpers/boot_strap_form_builder.rb
class BootStrapFormBuilder < ActionView::Helpers::FormBuilder
def text_field(method, options={})
t = @template
t.content_tag(:div, :class => "clearfix#{' error' unless @object.errors[method].blank?}") {
t.concat(t.label_tag method)
t.concat(t.content_tag(:div, :class => "input#{' error' unless @object.errors[method].blank?}") {
t.concat(super method)
if @object.errors[method].present?
t.concat(t.content_tag(:span, options[:help_text], :class => 'help-inline'))
end
})
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment