forked from stefankroes/ancestry
-
Notifications
You must be signed in to change notification settings - Fork 3
Ancestry in Rails Admin
computeus edited this page Mar 2, 2013
·
7 revisions
Category model snippet:
class Category < ActiveRecord::Base
attr_accessible :name, :parent_id
has_ancestry
Rails admin configuration snippet :
config.model Category do
field :name
field :parent_id, :enum do
enum do
except = bindings[:object].id.nil? ? 0 : bindings[:object].id
Category.where("id != ?", except).map { |c| [ c.name, c.id ] }
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