Module: CollectiveIdea::Acts::NestedSet::Helper

Defined in:
lib/awesome_nested_set/helper.rb

Overview

This module provides some helpers for the model classes using acts_as_nested_set. It is included by default in all views.

Instance Method Summary collapse

Instance Method Details

#nested_set_options(class_or_item, mover = nil, &block) ⇒ Object

Returns options for select. You can exclude some items from the tree. You can pass a block receiving an item and returning the string displayed in the select.

Params

* +class_or_item+ - Class name or top level times
* +mover+ - The item that is being move, used to exlude impossible moves
* +&block+ - a block that will be used to display: { |item, descendants, level| ... }

Usage

<%= f.select :parent_id, nested_set_options(Category, @category) { |item, descendants, level|
    "#{'–' * level} #{item.name}"
  }) %>


23
24
25
26
27
# File 'lib/awesome_nested_set/helper.rb', line 23

def nested_set_options(class_or_item, mover = nil, &block)
  class_or_item.traverse(true, mover) do |item, descendants, level|
    [ block.call(item, descendants, level), item.id ]
  end
end