Module: ActiveScaffold::Bridges::Ancestry::FormColumnHelpers

Defined in:
lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb

Instance Method Summary collapse

Instance Method Details

#active_scaffold_input_ancestry(column, options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb', line 18

def active_scaffold_input_ancestry(column, options)
  record = options[:object]
  select_options = []
  select_control_options = {:selected => record.parent_id}
  select_control_options[:include_blank] = as_(:_select_) if record.parent_id.nil?
  method = column.options[:label_method] || :to_label
  traverse_ancestry = proc do |key, value|
    unless key == record
      select_options << ["#{'__' * key.depth}#{key.send(method)}", key.id]
      value.each(&traverse_ancestry) if value.is_a?(Hash) && !value.empty?
    end
  end
  record.class.arrange.each(&traverse_ancestry)
  select(:record, :ancestry, select_options, select_control_options, options)
end