Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Ancestry in Rails Admin

Jiri Kolarik edited this page · 8 revisions

Category model snippet:

class Category < ActiveRecord::Base
  attr_accessible :name, :parent_id
  has_ancestry

  def parent_enum
    Category.where.not(id: id).map { |c| [ c.name, c.id ] }
  end
end

Rails admin configuration snippet :

config.model Category do
  field :name
  field :parent_id, :enum do
    enum_method do
      :parent_enum
    end
  end
end

Note that parent_id is virtual attribute and is not column in database.

Drag and drop tree view plugin for rails_admin: https://github.com/dalpo/rails_admin_nestable

Something went wrong with that request. Please try again.