0

I've got a model "Window" with has_many relationship to another model "WindowItems". The WindowItems has a self referencing relationship (so it can have nested children of itself).

I've got an activeadmin resource for window like this:

show :title => :name do

attributes_table do
  row :name
  row :column_position
  row :window_type
  row :column_count
  row :active
  row :page_position
  row :collapsible
  row :icon_id
  row :created_at
  row :updated_at
end

div :class => "accordion" do
  if window.window_items.count > 0
    panel "Window Items (#{window.window_items.count})" do

      table_for window.window_items do
        column "Name" do |a|
          link_to a.name, admin_window_item_path(a.id)
        end
        column :active
        column :link
        column :icon
        column :window
      end
    end
  end
end # end accordion

end

So right now, this is showing all window items, but instead I would only like it to show the parent window items (leaving the child window items off).

How can I filter the records that are shown on the panel "window items do" block?

Thanks

Sean
  • 1,078
  • 14
  • 25

2 Answers2

0

I think your problem would be solved pretty easily if you add a parent_id to your WindowItem model. All the nested children would have parent_id's referring to their parent where your top level items would have no parent_id.

Chris Barretto
  • 9,379
  • 3
  • 42
  • 45
  • sorry I wasn't more clear on this, I actually do have a parent id. I'm trying to show the children of this panel (which would be like you suggested, the ones with empty parent_id). I just don't know how to filter records shown on the activeadmin table_for thanks! – Sean Feb 23 '13 at 19:30
0

I finally figured it out. I just added a scope in the model and then referenced that scope.

Scope:

scope :is_parent, where('parent_window_item_id IS NULL || parent_window_item_id = ""')

and in activeadmin resource:

table_for window.window_items.is_parent do
....
end
Sean
  • 1,078
  • 14
  • 25