Class: BootstrapFormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
lib/generators/bootstrap_forms/install/templates/bootstrap_form_builder.rb

Instance Method Summary collapse

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
  @options = args.extract_options!
  @args = args
  
  clearfix_div do
    label_field + input_div do
      extras do
        (: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)
        
            (:li) do
              (:label) do
                checkbox + (: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 collection_radio_buttons(attribute, records, record_id, record_name, *args)
  @name = attribute
  @options = args.extract_options!
  @args = args
  
  clearfix_div do
    label_field + input_div do
      extras do
        (:ul, :class => 'inputs-list') do
          records.collect do |record|
            element_id = "#{object_name}_#{attribute}_#{record.send(record_id)}"
            radiobutton = radio_button_tag("#{object_name}[#{attribute}][]", record.send(record_id), object.send(attribute) == record.send(record_id), :id => element_id)
          
            (:li) do
              (:label) do
                radiobutton + (:span, record.send(record_name))
              end
            end
          end.join('').html_safe
        end
      end
    end
  end
end

#error_messagesObject



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 error_messages
  if object.errors.full_messages.any?
    (:div, :class => 'alert-message block-message error') do
      link_to('×'.html_safe, '#', :class => 'close') +
      (:p, "<strong>Oh snap! You got an error!</strong> Fix the errors below and try again.".html_safe) +
      (:ul) do
        object.errors.full_messages.map do |message|
          (:li, message)
        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
  @options = args.extract_options!
  @args = args
  
  @options[:class] = 'btn primary'
  
  (:div, :class => 'actions') do
    super(name, *(args << @options)) + ' ' + 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
  @options = args.extract_options!
  @args = args
  
  clearfix_div do
    label_field + input_div do
      extras do
        (:span, :class => 'uneditable-input') do
          @options[:value] || object.send(@name.to_sym)
        end
      end
    end
  end
end