Class: BootstrapFormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- BootstrapFormBuilder
- Defined in:
- lib/generators/bootstrap_forms/install/templates/bootstrap_form_builder.rb
Instance Method Summary collapse
- #collection_check_boxes(attribute, records, record_id, record_name, *args) ⇒ Object
- #collection_radio_buttons(attribute, records, record_id, record_name, *args) ⇒ Object
- #error_messages ⇒ Object
- #submit(name = nil, *args) ⇒ Object
- #uneditable_field(name, *args) ⇒ Object
Instance Method Details
#collection_check_boxes(attribute, records, record_id, record_name, *args) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/generators/bootstrap_forms/install/templates/bootstrap_form_builder.rb', line 34 def collection_check_boxes(attribute, records, record_id, record_name, *args) @name = attribute = args. @args = args clearfix_div do label_field + input_div do extras do content_tag(:ul, :class => 'inputs-list') do records.collect do |record| element_id = "#{object_name}_#{attribute}_#{record.send(record_id)}" checkbox = check_box_tag("#{object_name}[#{attribute}][]", record.send(record_id), object.send(attribute).include?(record.send(record_id)), :id => element_id) content_tag(:li) do content_tag(:label) do checkbox + content_tag(:span, record.send(record_name)) end end end.join('').html_safe end end end + hidden_field_tag("#{object_name}[#{attribute}][]") end end |
#collection_radio_buttons(attribute, records, record_id, record_name, *args) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/generators/bootstrap_forms/install/templates/bootstrap_form_builder.rb', line 59 def (attribute, records, record_id, record_name, *args) @name = attribute = args. @args = args clearfix_div do label_field + input_div do extras do content_tag(:ul, :class => 'inputs-list') do records.collect do |record| element_id = "#{object_name}_#{attribute}_#{record.send(record_id)}" = ("#{object_name}[#{attribute}][]", record.send(record_id), object.send(attribute) == record.send(record_id), :id => element_id) content_tag(:li) do content_tag(:label) do + content_tag(:span, record.send(record_name)) end end end.join('').html_safe end end end end end |
#error_messages ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/generators/bootstrap_forms/install/templates/bootstrap_form_builder.rb', line 4 def if object.errors..any? content_tag(:div, :class => 'alert-message block-message error') do link_to('×'.html_safe, '#', :class => 'close') + content_tag(:p, "<strong>Oh snap! You got an error!</strong> Fix the errors below and try again.".html_safe) + content_tag(:ul) do object.errors..map do || content_tag(:li, ) end.join('').html_safe end end else '' # return empty string end end |
#submit(name = nil, *args) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/generators/bootstrap_forms/install/templates/bootstrap_form_builder.rb', line 100 def submit(name = nil, *args) @name = name = args. @args = args [:class] = 'btn primary' content_tag(:div, :class => 'actions') do super(name, *(args << )) + ' ' + link_to('Cancel', :back, :class => 'btn') end end |
#uneditable_field(name, *args) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/generators/bootstrap_forms/install/templates/bootstrap_form_builder.rb', line 84 def uneditable_field(name, *args) @name = name = args. @args = args clearfix_div do label_field + input_div do extras do content_tag(:span, :class => 'uneditable-input') do [:value] || object.send(@name.to_sym) end end end end end |