覆蓋沒有「新建!」的新控制器不顯示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
謝謝。請看我做的更正。還是行不通。 – amj