1

覆盖没有“新!”的新控制器 不显示 ActiveAdmin 布局。但是当我添加“新!”时 尽管我做了“@resource.build_synchronization”,但没有出现嵌套的“同步”表单。不太确定我在这里做错了什么。

案例 #1(ActiveAdmin 布局消失了)

ActiveAdmin.register Resource do
  controller do
      # This code is evaluated within the controller class
      def new
        @resource = Resource.new
        @resource.build_synchronization
      end
  end
end

案例#2(没有出现嵌套表单同步)

ActiveAdmin.register Resource do
  controller do
      # This code is evaluated within the controller class
      def new
        @resource = Resource.new
        @resource.build_synchronization
        new!

      end
  end
end

视图\管理员\资源\new.html.erb

<%= semantic_form_for [:admin, @resource] do |form| %>
    <%= form.inputs "Resource", :id => "resource" do %>
        <%= form.input :name %>
        <%= form.semantic_fields_for :synchronization do |sync| %>
            <% sync.inputs  :name => "Synchronization", :id => "synchronization"  do %>
                <%= sync.input :start_datetime, :as => :datetime %>
                <%= sync.input :repeat_interval, :as => :radio, :collection => @intervals %>
                <%= sync.input :repeat_type, :as => :select, :collection => ["Manual", "Automatic"] %>
            <% end %>
        <% end %>
    <% end %>
    <%= form.buttons %>
<% end %>
<% end %>

楷模:

class Resource < ActiveRecord::Base
  has_one :synchronization
  accepts_nested_attributes_for :synchronization
end


class Synchronization < ActiveRecord::Base
  belongs_to :resource
  has_many :mappings
  accepts_nested_attributes_for :mappings
  #validates_presence_of :start_datetime
end
4

2 回答 2

2

对于 CRUD 操作,活动管理员不要使用标准布局

lib/active_admin/resource_controller.rb

    # Determine which layout to use.
    #
    #   1.  If we're rendering a standard Active Admin action, we want layout(false)
    #       because these actions are subclasses of the Base page (which implementes
    #       all the required layout code)
    #   2.  If we're rendering a custom action, we'll use the active_admin layout so
    #       that users can render any template inside Active Admin.
    def determine_active_admin_layout
      ACTIVE_ADMIN_ACTIONS.include?(params[:action].to_sym) ? false : 'active_admin'
    end

您可以手动定义布局

  controller do
    layout 'active_admin', :only => [:new]
  end
于 2011-11-09T01:13:32.297 回答
1

您需要将form.semantic_fields_for语句放在一个form.inputs块内。

另外,我form.buttons既不会放在form.semantic_fields_for块也不会放在form.inputs块内。它应该是semantic_form_for块下的直接子项(这不是导致您的问题的原因,而只是您通常放置它的位置)。

于 2011-10-10T09:21:36.407 回答