Class: ActiveAdmin::FormBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/activeadmin_draggable/sortable_tree.rb

Overview

This form helper allows us to create form for nested belongs_to association.

Instance Method Summary collapse

Instance Method Details

#has_one_nested(association, options = {}, &block) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/activeadmin_draggable/sortable_tree.rb', line 56

def has_one_nested(association, options = {}, &block)
  options = { :for => association }.merge(options)
  options[:class] ||= ""
  options[:class] << "inputs has_one_field"

  #looks dirty...but works (still better than active admin's way)
  if object.new_record?
    content = inputs_for_nested_attributes :for => [association, object.class.reflect_on_association(association).klass.new],
                &block
    form_buffers.last << content.html_safe
  else
    content = inputs options, &block
  end
end