Overriding a new controller without ‘new!’ does not display ActiveAdmin layout. But then when I added ‘new!’ nested ‘synchronization’ form is not appearing although I did ‘@resource.build_synchronization’. Not so sure what I’m doing wrong here.
case #1 (ActiveAdmin layout is gone)
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
case #2 (nested form synchronization does not appear)
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
views\admin\resources\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 %>
models:
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
You need to put the
form.semantic_fields_forstatement inside aform.inputsblock.Also, I would not put
form.buttonsinside neither theform.semantic_fields_forblock nor aform.inputsblock. It should be a direct child under thesemantic_form_forblock (this is not what is causing your problem, but just the location where you would normally put this).