Answer the question
In order to leave comments, you need to log in
Output list and tree view for Ancesty?
Hello!
Using a bunch of gems: rails_admin + ancesrty + rails_admin_nestable
I'm trying to make a dropdown list when creating a page to specify the parent.
in Page.rb:
def self.ancestry_options(items)
result = []
items.map do |item, sub_items|
result << [yield(item), item.id]
result += ancestry_options(sub_items) {|i| "#{'-' * i.depth} #{i.title}" }
end
result
end
field :ancestry, :enum do
enum do
Page::ancestry_options(Page.unscoped.arrange(:order => 'id')) { |i| "#{'-' * i.depth} #{i.title}" }
end
end
root_page - 1
Videos - 2
Video 1 - 3
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question