Partially displayed twice in ActiveAdmin

My part is displayed twice: at the top of the page and in the place where it should have been. Apparently this only happens when I have ActiveAdmin-specific code (table_for).

Any help is appreciated. Below are some snippets of code that I use.

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 the _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 %> 
+8
ruby-on-rails activeadmin
source share
1 answer

From what I read, ActiveAdmin will automatically get a partial path based on the current model / resource name. This means that passing "child_list" will result in
"/admin/process_nodes/_child_list.html.erb" .

Use will be

 div render "child_list", :locals { :parent => process_node } 

Also, it seems like it would be better to include the unless in the unless panel pane. Then you do not have to add an unnecessary rendering call if there are no subprocesses.

 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 do not know if using partial benefits is a big benefit. I do not know if you have anything else in partial, but you can write it like this.

 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 
+5
source share

All Articles