stefankroes / ancestry

Organise ActiveRecord model into a tree structure
MIT License
3.72k stars 458 forks source link

having trouble displaying tree in select across different models/controllers #604

Closed mices closed 1 year ago

mices commented 1 year ago

Please help? In my items index view I'm trying to create a collection_select list using the Category model to allow the user to select the Category so I need a hyphen character for each of a categories parents with the list arranged by parents/children I have a routine defined in the Category model and I'm calling it in my view undefined local variable or method `depth' for ItemType:Class from Category.rb: def self.name_for_selects "#{'-' * depth} #{name}" end and from items/index.html.erb <%= f.collection_select :category_id, @categories, :id, Category.name_for_selects, :include_blank => true %>