Class: Trestle::Form::Automatic
- Inherits:
-
Trestle::Form
- Object
- Trestle::Form
- Trestle::Form::Automatic
- Defined in:
- lib/trestle/form/automatic.rb
Instance Attribute Summary
Attributes inherited from Trestle::Form
Instance Method Summary collapse
-
#initialize(admin) ⇒ Automatic
constructor
A new instance of Automatic.
Methods inherited from Trestle::Form
Constructor Details
#initialize(admin) ⇒ Automatic
Returns a new instance of Automatic.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/trestle/form/automatic.rb', line 4 def initialize(admin) @block = Proc.new do admin.default_attributes.each do |attribute| next if attribute.primary_key? next if attribute.inheritance_column? next if attribute.counter_cache? case attribute.type when :association = attribute.association_class.all.map { |instance| [display(instance), instance.id] } prompt = "- Select #{admin.model.human_attribute_name(attribute.association_name)} -" select attribute.name, , include_blank: prompt when :text text_area attribute.name when :date date_field attribute.name when :datetime datetime_field attribute.name when :boolean check_box attribute.name else text_field attribute.name end end end end |