Question

I have a model named Tags where each tag has a name and description but a tag can be the parent for other tags.

I was thinking of adding a parent_id to my model but I want to know if Rails Admin can be configured to relate the child to a parent (another record from same model).

Thanks :)

Was it helpful?

Solution

Found it on: Creating a model that has a tree structure

Thanks to coreyward :)

class Tag < ActiveRecord::Base
    attr_accessible :description, :name, :parent_id
    has_many :children, class_name: "Tag", foreign_key: "parent_id"
    belongs_to :parent, class_name: "Tag",primary_key: "id"
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top