Sha256: e2076e3c3cf803bfa0dc6065d1622ccf9ef15b1a7161f2fbe36c6d3677e5f4a8
Contents?: true
Size: 1.69 KB
Versions: 1
Compression:
Stored size: 1.69 KB
Contents
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.messages.not_saved", :count => @object.errors.count, :resource => @object.class.model_name.human.downcase ) html = <<-HTML <div class="alert alert-error"> <p><b>#{sentence}</b></p> <ul>#{messages}</ul> </div> 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) else super(name) 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 private 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
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
booter-0.2.3 | app/form_builders/bootstrap_form_builder.rb |