Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partial is rendered twice in ActiveAdmin

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
%>
like image 796
shoegazerpt Avatar asked Aug 09 '12 21:08

shoegazerpt


1 Answers

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
like image 119
Baylor Rae' Avatar answered Oct 18 '22 10:10

Baylor Rae'