Class: MonologueAdminFormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- MonologueAdminFormBuilder
- Defined in:
- app/form_builders/monologue_admin_form_builder.rb
Instance Method Summary collapse
- #check_box(name, *args) ⇒ Object
- #collection_check_boxes(attribute, records, record_id, record_name) ⇒ Object
- #error_messages ⇒ Object
- #submit(*args) ⇒ Object
Instance Method Details
#check_box(name, *args) ⇒ Object
12 13 14 15 16 17 18 |
# File 'app/form_builders/monologue_admin_form_builder.rb', line 12 def check_box(name, *args) = args. required = object.class.validators_on(name).any? { |v| v.kind_of? ActiveModel::Validations::PresenceValidator } content_tag :label, class: (required ? "required checkbox inline" : "checkbox inline") do super + ([:label] || name) end end |
#collection_check_boxes(attribute, records, record_id, record_name) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'app/form_builders/monologue_admin_form_builder.rb', line 20 def collection_check_boxes(attribute, records, record_id, record_name) content_tag :div, class: "field" do @template.hidden_field_tag("#{object_name}[#{attribute}][]") + records.map do |record| element_id = "#{object_name}_#{attribute}_#{record.send(record_id)}" checkbox = @template.check_box_tag("#{object_name}[#{attribute}][]", record.send(record_id), object.send(attribute).include?(record.send(record_id)), id: element_id) checkbox + " " + @template.label_tag(element_id, record.send(record_name)) end.join(tag(:br)).html_safe end end |
#error_messages ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/form_builders/monologue_admin_form_builder.rb', line 37 def if object.errors..any? content_tag(:div, class: "alert alert-error error_messages") do content_tag(:strong, "Invalid Fields") + content_tag(:ul) do object.errors..map do |msg| content_tag(:li, msg[1][0]) end.join.html_safe end end end end |
#submit(*args) ⇒ Object
31 32 33 34 35 |
# File 'app/form_builders/monologue_admin_form_builder.rb', line 31 def submit(*args) content_tag :div, class: "form-actions" do super end end |