Skip to content

Instantly share code, notes, and snippets.

@rev087
Created September 6, 2011 02:09
Show Gist options
  • Save rev087/1196388 to your computer and use it in GitHub Desktop.
Save rev087/1196388 to your computer and use it in GitHub Desktop.
Rails FormBuilder to be used with Bootstrap from Twitter
class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
['text_field', 'text_area'].each do |helper|
define_method helper do |field, *args|
options = args.detect{ |a| a.is_a?(Hash) } || {}
if @object.errors[field].any?
'<div class="clearfix error">'.html_safe +
(self.label field) +
'<div class="input">'.html_safe +
(super field, *args) +
'<span class="help-inline">'.html_safe + @object.errors[field].join('; ') + '</span>'.html_safe +
'</div></div>'.html_safe
else
'<div class="clearfix">'.html_safe +
(self.label field) +
'<div class="input">'.html_safe +
(super field, *args) +
'</div></div>'.html_safe
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment