Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9678 (new enhancement)

Opened 8 months ago

Last modified 5 months ago

[PATCH] View helper method for acts_as_nested_set

Reported by: jcoglan Assigned to: core
Priority: normal Milestone: 2.x
Component: Plugins Version: edge
Severity: normal Keywords: unverified
Cc:

Description

This patch adds a nested_set_list helper method to acts_as_nested_set, which produces a nested HTML list when given a collection of records from a nested set model. See the docs in the patch for a full example.

Attachments

nested_set_helper.diff (3.0 kB) - added by jcoglan on 09/25/07 16:27:54.

Change History

09/25/07 16:27:54 changed by jcoglan

  • attachment nested_set_helper.diff added.

09/25/07 16:29:45 changed by jcoglan

Not sure how to get SVN to create this patch successfully. init.rb needs the following line:

ActionView::Base.send :include, ActionView::Helpers::NestedSetHelper

The patch contains all the code for that module.

10/18/07 19:35:45 changed by Henrik N

heirarchy -> hierarchy in the patch :)

10/22/07 16:42:53 changed by josh

Seems really niche and hard to extend. And I think the ActsAs plugins are supposed to be and should stay really simple AR extensions.

-1

12/21/07 02:01:59 changed by danielmorrison

jcoglan: you might want to check out our awesome_nested_set plugin, (which itself is a refactoring and cleanup of better_nested_set). http://source.collectiveidea.com/public/rails/plugins/awesome_nested_set/

IMHO, acts_as_nested_set is dead and there are better replacements.

Specifically, our recursion methods make so you could do your example with

<ul>
  <% rails_project_files.roots.recurse do |file, block| -%>
   <li>
      <%=h file.name %>
      <!-- an empty ul is invalid xhtml! -->
      <% unless children.children.empty? -%>
        <ul><% block.call %></ul>
      <% end %>
    </li>
  <% end -%>
</ul>

A little more code, but more flexible.

Our docs suck, but we're using the code every day in production code and are open to feedback.