Closed benadler closed 15 years ago
I worked around this issue by editing the CollectiveIdea::Acts::NestedSet::Helper method nested_set_options. For me the file was located at vendor/plugins/awesome_nested_set/lib/awesome_nested_set/helper.rb Basically I prepended a blank array entry onto the front of the results variable before it is returned. result.unshift([''])
def nested_set_options(class_or_item, mover = nil) class_or_item = class_or_item.roots if class_or_item.is_a?(Class) items = Array(class_or_item) result = [] items.each do |root| result += root.self_and_descendants.map do |i| if mover.nil? || mover.new_record? || mover.move_possible?(i) [yield(i), i.id] end end.compact end result.unshift(['']) end
I think it would be a valuable addition to the helper method to offer the ability to pass an options hash in after the class_or_item. The :mover could be included as one of the options, since it is optional anyway. Perhaps a branch and test will follow soon.
you can do this without modifying the code:
<%= f.select :parent_id, [nil] + nested_set_options(Storage, @storage) {|i| "#{'-' i.level 2} #{i.name}" } %>
I love ruby's simplicity. And rails. Thanks, Brandon!
I'm a rails-newbie trying to create multiple root nodes using a_n_s. I wasn't sure whether multiple roots are supported, but methods like "all_roots_valid?()" lead me to suspect so.
When using
<%= f.select :parent_id, nested_set_options(Storage, @storage) {|i| "#{'-' * i.level * 2} #{i.name}" } %>
in my new-view, I can select all existing nodes as parent for my new node. But I just cannot figure out how to create further root-nodes (parent_id=NULL) using this approach, because the generated
Also, I'd prefer to indent children in the selectbox using " " instead of "-", but the html is escaped to " ", so that doesn't work. Any ideas how I could get that working?
I hope this is the right forum to ask these kinds of questions. thanks! ben