active_admin-sortable_tree causes error when trying to use it

Assuming the following:

ActiveAdmin.register Section do
  menu :label => "Sections used in the menu"
  menu :parent => "CMS", priority: 1
  permit_params :name,:section_type, :visible,sections: [], sections_id: []

  sortable tree: true,
           sorting_attribute: :position,
           max_levels: 1,
           collapsible: true

  index as: :sortable do
    selectable_column
    id_column

    column :name
    column :section_type
    column :visible do |section|
      section.visible ? status_tag("yes",class: :ok) : status_tag("no")
    end
    actions
  end
end

incase it's needed, section.rb:

class Section < ActiveRecord::Base

  belongs_to :parent, class_name: self.to_s, foreign_key: 'section_id'
  has_many :children, class_name: self.to_s, foreign_key: 'section_id'

  scope :roots, -> {where(section_id: nil)}
end

I get the following Error:

undefined local variable or method `selectable_column' for "                  <div class=\"index_as_sortable\"></div>\n":ActiveAdmin::Views::IndexAsSortable

This goes away if I remove as: :sortable but this is of course not going to work (obviously as I can't then use the sortable tree).

I'm guessing the error happens because by doing as: :sortable causes the execution context for the index block to change and the new execution context doesn't have the index methods.

Regardless, how do I fix this?

1 answer

  • answered 2017-10-11 10:04 Thermatix

    Ok, so I was right, the execution context changes from a standard index to a IndexAsSortable as a result I wrongly assumed that the same methods would exist but they don't, hence things like column and so on don't exist.