Closed mices closed 1 year ago
It errors out on line 12 of item_type.rb which is the second line shown here "hash||=arrange(options)" definitions from item_type.rb It would seem the error would be caused by arrange not being defined:
def self.arrange_as_array(options={}, hash=nil)
hash ||= arrange(options)
arr = []
hash.each do |node, children|
arr << node
arr += arrange_as_array(options, children) unless children.nil?
end
arr
end
def name_for_selects
"#{'-' * depth} #{name}"
end
def possible_parents
parents = ItemType.arrange_as_array(:order => 'name')
return new_record? ? parents : parents - subtree
end
This is how I'm using arrange_as_array instantiating @item_types
in my controller:
def get_item_types
#@item_types=ItemType.arrange_as_array
@item_types = ItemType.arrange_as_array({:order => 'name'})
#@item_types = ItemType.order(:names_depth_cache).map { |c| ["-" * c.depth + c.name,c.id] }
end
Is this related to #605 Did you find your answer?
If this is related to #610 could we consolidate the discussion over there?
Thanks
Have you tried something like this?
items = ItemType.all
@item_types = ItemType.sort_by_ancestry(items, &:name).map { |c| ["-" * c.depth + c.name,c.id] }
You may be able to get away without the block sort
items = ItemType.all.ordered_by_ancestry_and(:name)
@item_types = ItemType.sort_by_ancestry(items).map { |c| ["-" * c.depth + c.name,c.id] }
Try those out and see what works best for you
You also want to probably add the ItemType.all.includes(:item_property)
to remove your N+1
@mices I updated the wiki page. Please let me know if that code works for you
You haven't replied to my messages in 2 weeks. I'm hoping that means you had success. Best of luck
I'm using item_type model name instead of category, i know that was a mistake but now arrange_as_array seems to be erroring out ...
edit: kbrock added code block