My partial is being rendered twice: at the top of the page and at the place where it's supposed to. Apparently, this only happens when I have ActiveAdmin-specific code (table_for).
Any help is greatly appreciated. Below are some code snippets I'm using.
In my active admin file:
panel "Children - SubProcesses" do
text_node link_to "New", new_admin_sub_process_node_path(:parent_id => process_node.id)
div render :partial => "/admin/process_nodes/child_list", :locals => { :parent => process_node }
end
In _child_list.html.erb file
<%=
unless parent.children.empty?
table_for parent.children do
column :id
column :name
column "Actions" do |child_node|
text_node link_to "View", admin_process_node_path(child_node)
text_node " "
text_node link_to "Edit", edit_admin_process_node_path(child_node)
text_node " "
text_node link_to "Delete", admin_process_node_path(child_node), :method => :delete, :confirm => "Delete?"
end
end
end
%>
From what I've read, ActiveAdmin will automatically get the path of the partial based on the current model/resource name. Which means passing "child_list"
will result in
"/admin/process_nodes/_child_list.html.erb"
.
Usage would be
div render "child_list", :locals { :parent => process_node }
Also, it seems like it would be better to include your unless
statement within the ActiveAdmin panel block. Then you won't have to add an unnecessary render call if there are no sub processes.
panel "Children - SubProcesses" do
text_node link_to "New", new_admin_sub_process_node_path(:parent_id => process_node.id)
unless parent.children.empty?
div render "child_list", :locals { :parent => process_node }
end
end
Finally, I don't know if using a partial is a great benefit. I don't know if you have anything else in the partial, but you could write it this way.
panel "Children - SubProcesses" do
text_node link_to "New", new_admin_sub_process_node_path(:parent_id => process_node.id)
unless parent.children.empty?
table_for parent.children do
column :id
column :name
column "Actions" do |child_node|
text_node link_to "View", admin_process_node_path(child_node)
text_node " "
text_node link_to "Edit", edit_admin_process_node_path(child_node)
text_node " "
text_node link_to "Delete", admin_process_node_path(child_node), :method => :delete, :confirm => "Delete?"
end
end
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With