ActiveAdmin'show'布局与edit / new不同

时间:2014-10-02 16:45:48

标签: activeadmin

我已为新/编辑自定义表单,以便为表单字段使用两列布局。 定制使用formtastic。

默认情况下,“show”的布局是否应该相同?相反,我得到activeadmin默认每行显示一个字段。 如何在“show”中显示与我的表单(新/编辑)页面相同的布局? enter image description here

2 个答案:

答案 0 :(得分:1)

默认情况下,展示页面有自己的布局,因此您必须使用一些css来排列输入,或者您可以覆盖此方法:

https://github.com/activeadmin/activeadmin/blob/master/lib/active_admin/views/components/attributes_table.rb#L22-L43

@collection.each_slice(2) do |records|
 td do
   content_for(record[0], block || title)
 end
 td do
   content_for(record[1], block || title)
 end
end

或者创建一个新的,并在show block中使用它:

module ActiveAdmin
  module Views

    class AttributesTable < ActiveAdmin::Component
      builder_method :attributes_table_for

      def row_with_two_fields(*args, &block)
        title   = args[0]
        options = args.extract_options!
        classes = [:row]
        if options[:class]
          classes << options[:class]
        elsif title.present?
          classes << "row-#{title.to_s.parameterize('_')}"
        end
        options[:class] = classes.join(' ')

        @table << tr(options) do
          th do
            header_content_for(title)
          end
          @collection.each_slice(2) do |records|
            td do
              content_for(record[0], block || title)
            end
            td do
              content_for(record[1], block || title)
            end
          end
        end
      end
  end
end

或类似的东西......我没有尝试过。

答案 1 :(得分:0)

我最终做了CSS hack

show do
panel "Mandatory Details" do
attributes_table_for contract do
    row :account, :class => "column1"
    row :customer, :class => "column2"
end
end 
panel "Dates And Financials" do
    attributes_table_for contract do
        row :start_date, :class => "column1"
        row :current_end_date, :class => "column2"
        row :end_date_w_options, :class => "column1"
    end
  end