Class: MonologueAdminFormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
app/form_builders/monologue_admin_form_builder.rb

Instance Method Summary collapse

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)
  options = args.extract_options!
  required = object.class.validators_on(name).any? { |v| v.kind_of? ActiveModel::Validations::PresenceValidator }
   :label, class:  (required ? "required checkbox inline" : "checkbox inline") do
    super + (options[: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)
   :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_messagesObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/form_builders/monologue_admin_form_builder.rb', line 37

def error_messages
  if object.errors.full_messages.any?
    (:div, class: "alert alert-error error_messages") do
      (:strong, "Invalid Fields") +
      (:ul) do
        object.errors.messages.map do |msg|
          (: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)
   :div, class:  "form-actions" do
    super
  end
end