Sha256: 42daa7d6d50f6a8204d54bf3be23b78394de7de4af7aa96652a249474f75bd40

Contents?: true

Size: 1.48 KB

Versions: 2

Compression:

Stored size: 1.48 KB

Contents

module Trestle
  class Form
    class Automatic < Form
      def initialize(admin)
        @block = Proc.new do |instance|
          admin.default_form_attributes.each do |attribute|
            if attribute.array?
              if [:string, :text].include?(attribute.type)
                select attribute.name, nil, {}, { multiple: true, data: { tags: true, select_on_close: true }}
              end
            else
              case attribute.type
              when :association
                if attribute.polymorphic?
                  static_field attribute.name do
                    associated_instance = instance.public_send(attribute.association_name)
                    admin_link_to format_value(associated_instance), associated_instance
                  end
                else
                  prompt = I18n.t("admin.form.select.prompt", default: "- Select %{attribute_name} -", attribute_name: admin.human_attribute_name(attribute.association_name))

                  select attribute.name, attribute.association_class.all, include_blank: prompt
                end
              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
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
trestle-0.8.5 lib/trestle/form/automatic.rb
trestle-0.8.4 lib/trestle/form/automatic.rb