Class: Bhf::ActionView::FormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Includes:
ActionView::Helpers::FormTagHelper
Defined in:
lib/bhf/action_view/form_builder.rb

Instance Method Summary collapse

Instance Method Details

#error_label(name, message) ⇒ Object



5
6
7
# File 'lib/bhf/action_view/form_builder.rb', line 5

def error_label(name, message)
  label name, "#{object.class.human_attribute_name(name)} #{message}"
end

#field_errors(field) ⇒ Object



9
10
11
# File 'lib/bhf/action_view/form_builder.rb', line 9

def field_errors(field)
  object.errors[field.to_sym]
end

#field_has_errors?(field) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/bhf/action_view/form_builder.rb', line 13

def field_has_errors?(field)
  field_errors(field).any?
end

#many_to_many_check_box(obj, ref_name, params, hide_label = false, checked = false, bhf_primary_key = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bhf/action_view/form_builder.rb', line 17

def many_to_many_check_box(obj, ref_name, params, hide_label = false, checked = false, bhf_primary_key = nil)
  mm = :has_and_belongs_to_many
  bhf_primary_key ||= obj.send(obj.class.bhf_primary_key).to_s
  unless checked
    checked = if params[mm] && params[mm][ref_name]
      params[mm][ref_name][bhf_primary_key] != ''
    else
      object.send(ref_name).include?(obj)
    end
  end
  
  html = hidden_field_tag("#{mm}[#{ref_name}][#{bhf_primary_key}]", '', id: "hidden_#{mm}_#{ref_name}_#{bhf_primary_key}")
  html = html+' '+check_box_tag("#{mm}[#{ref_name}][#{bhf_primary_key}]", bhf_primary_key, checked)
  html = html+' '+label_tag("#{mm}_#{ref_name}_#{bhf_primary_key}", obj.to_bhf_s) unless hide_label
  
  html
end