Class: TableFormBuilder::Builder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
lib/table_form_builder/builder.rb

Instance Method Summary collapse

Instance Method Details

#actions(&block) ⇒ Object



39
40
41
42
43
# File 'lib/table_form_builder/builder.rb', line 39

def actions(&block)
			@template.(:tr) do
    @template.(:th) + @template.(:td, @template.capture(&block))
  end
end

#check_box(field, *args) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/table_form_builder/builder.rb', line 16

def check_box(field, *args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  label   = label(field, options[:label])
  extra   = options[:extra].nil? ? "" : @template.(:span, :class => "extra") { options[:extra] }
  @template.(:tr) do
    @template.(:th) + @template.(:td, super(field, *args) + label + extra)
  end
end

#generate_error_message(field, error) ⇒ Object



49
50
51
# File 'lib/table_form_builder/builder.rb', line 49

def generate_error_message(field, error)
  "#{field.to_s.humanize} #{error}"
end

#generate_errors(field) ⇒ Object



45
46
47
# File 'lib/table_form_builder/builder.rb', line 45

def generate_errors(field)
  @object.errors[field].collect{|e| @template.(:div, :class => "error"){generate_error_message(field, e)}}.join.html_safe
end

#group(text, &block) ⇒ Object



25
26
27
28
29
# File 'lib/table_form_builder/builder.rb', line 25

def group(text, &block)
	@template.(:tr) do
		@template.(:th, text) + @template.(:td, @template.capture(&block))
	end
end

#title(text) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/table_form_builder/builder.rb', line 31

def title(text)
  @template.(:tr) do
    @template.(:th) + @template.(:td) do
      @template.(:h3, text)
    end
  end
end