class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
delegate :content_tag, :safe_join, to: :@template
def errors_for
return "" if @object.errors.empty?
messages = @object.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
sentence = I18n.t(
"errors.template.header",
:count => @object.errors.count,
:model => @object.class.model_name.human
)
html = <<-HTML
HTML
html.html_safe
end
%w[email_field password_field text_field text_area].each do |method_name|
define_method method_name do |*args|
options = args.extract_options!
name = args.first
wrapper name, options do
if method_name == 'text_area'
super(name, rows: 7, class: 'input-xxlarge')
else
super(name, class: 'input-xxlarge')
end
end
end
end
def select(name, choices, options = {})
wrapper name do
super
end
end
def check_box(name)
wrapper name do
content_tag :label, class: 'checkbox' do
super(name)
end
end
end
def submit(value=nil)
content_tag :div, class: 'form-actions' do
super value, class: 'btn btn-primary'
end
end
def wrapper(name, options = {}, &block)
content_tag :div, class: ['control-group', ('error' if @object.errors[name].present?)] do
safe_join [
label(name, class: 'control-label'),
content_tag(:div, class: 'controls'){
safe_join [
yield,
(content_tag(:p, options[:hint], class: 'help-block') if options[:hint].present?)
]
}
]
end
end
end