覆盖没有“新!”的新控制器 不显示 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