Class: C::CFormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
app/helpers/c/c_form_builder.rb

Instance Method Summary collapse

Instance Method Details

#error_messagesObject



4
5
6
7
8
9
10
11
12
# File 'app/helpers/c/c_form_builder.rb', line 4

def error_messages
  return unless object.respond_to?(:errors) && object.errors.any?

  header = @template.(:h4, 'Errors prevented the form from saving', class: 'title-error')
  errors_array = object.errors.full_messages.map { |message| @template.(:li, message) }
  errors_list = @template.safe_join([header, @template.safe_join(errors_array)])

  @template.(:ul, @template.raw(errors_list), class: 'form_errors')
end

#image_field(method, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
# File 'app/helpers/c/c_form_builder.rb', line 28

def image_field(method, options = {})
  @template.field_set_tag '', class: 'image_field' do
    @template.(:span, method.to_s.titleize, class: 'fieldset-title') +
    hidden_field("#{method}_cache") +
      (@template.image_tag(@object.send(method)) || '') +
      file_field(method, options)
  end
end

#price_field(method, _options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/c/c_form_builder.rb', line 14

def price_field(method, _options={})
  @template.field_set_tag '', class: 'price_field' do
    @template.(:span, method.to_s.titleize.to_s, class: 'fieldset-title') +
    fields_for(method) do |builder|
      @template.(:div, class: 'gs') do
        @template.(:div, class: 'field field--inner-label g-1') { builder.label(:without_tax) + builder.number_field(:without_tax, step: 0.01, min: 0) } +
          @template.(:div, class: 'field field--inner-label g-1 g-gutter--narrow') { builder.label(:with_tax) + builder.number_field(:with_tax, step: 0.01, min: 0) } +
          @template.(:div, class: 'field field--inner-label g-1 g-gutter--narrow') { builder.label(:tax_rate) + builder.number_field(:tax_rate, step: 0.01, min: 0) }
      end +
        builder.label(:override) { builder.check_box(:override) + @template.(:span, 'Override tax rate', class: 'checkbox-span-label') }
    end
  end
end

#tiny_mce_text_area(method, tinymce_config = 'standard') ⇒ Object



37
38
39
40
# File 'app/helpers/c/c_form_builder.rb', line 37

def tiny_mce_text_area(method, tinymce_config='standard')
  text_area(method, class: 'tinymce') +
  @template.send("tinymce_#{tinymce_config}")
end