Created
September 6, 2011 02:09
-
-
Save rev087/1196388 to your computer and use it in GitHub Desktop.
Rails FormBuilder to be used with Bootstrap from Twitter
This file contains 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 | |
['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