2011-10-09 32 views
1

覆蓋沒有「新建!」的新控制器不顯示ActiveAdmin佈局。但是當我添加'新!'時雖然我做了'@ resource.build_synchronization',但嵌套'同步'表單沒有出現。不太確定我在這裏做錯了什麼。覆蓋控制器動作後,Rails ActiveAdmin佈局丟失

情況#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 

回答

1

你需要把form.semantic_fields_for語句form.inputs塊內。

此外,我不會把form.buttonsform.semantic_fields_for塊或form.inputs塊。它應該是semantic_form_for區塊下的直接孩子(這不是導致你的問題的原因,而只是你通常放置的位置)。

+0

謝謝。請看我做的更正。還是行不通。 – amj

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