`
orcl_zhang
  • 浏览: 243142 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

acts_as_tree

阅读更多
acts_as_tree:
http://snippets.dzone.com/tag/acts_as_tree

------------
// This takes a collection of acts_as_tree objects and creates a unordered list.
//
// Put this in your helper:
 def tree_ul(acts_as_tree_set, init=true, &block)
    if acts_as_tree_set.size > 0
      ret = '<ul>'
      acts_as_tree_set.collect do |item|
        next if item.parent_id && init
        ret += '<li>'
        ret += yield item
        ret += tree_ul(item.children, false, &block) if item.children.size > 0
        ret += '</li>'
      end
      ret += '</ul>'
    end
  end



// ... and this in your view:
 <%= tree_ul(@acts_as_list_collection) {|item| link_to h(item.name), :action => 'edit', :id => item } %>

分享到:
评论

相关推荐

    acts_as_category:想想acts_as_tree +权限

    #ActsAsCategory acts_as_category (Version 2.0 beta)acts_as_category,是acts_as插件在acts_as_tree风格的Ruby on Rails的ActiveRecord的模式,但有一些额外的功能,以及多种便捷视图助手。例子(有关实例方法和...

    acts_as_sane_tree:用于ActiveRecord和PostgreSQLSane树构建器

    acts_as_sane_tree (用一些理智的方法建造树木) 在Postgresql&gt; = 8.4的系统上,这是对act_as_tree的替代。这提供了什么 建立树木的快速方法。哪个版本的 轨道〜&gt; 4.1.0 轨道〜&gt; 4.0.0 导轨〜&gt; 3.2.0 轨道〜&gt; 3.1.0...

    Ruby-ActsAsTree扩展ActiveRecord添加亲子关系支持

    安装`ActsAsTree` gem后,你可以通过`gem 'acts_as_tree'`在你的`Gemfile`中添加依赖,并运行`bundle install`来安装。在代码中,你可以通过`require 'acts_as_tree'`来引入这个库。 在压缩包`amerine-acts_as_tree...

    Ruby-MongoidTreeMongoid文档树结构使用物化路径模式

    接着,为你的Mongoid模型添加`acts_as_tree`方法,这将启用树结构功能: ```ruby class Category include Mongoid::Document acts_as_tree end ``` 现在,你可以创建、查找和操作树节点: ```ruby # 创建节点 ...

    Acts-as-Orderable:Rails gem使ActiveRecord模型可以下订单并上下移动

    ActsAsOrderable安装 gem install acts_as_orderable并在您的Gemfile中: gem 'acts_as_orderable'型号声明: class CoolClass &lt; ActiveRecord xss=removed&gt; 0, :null =&gt; false它与acts_ac_tree一起很好地工作(每个...

    Rails中应用Ext.tree:以中国的省市地区三级联动选择为例

    本篇文章将深入探讨如何在Rails中利用`acts_as_nested_set` gem来实现中国省市地区的三级联动选择功能。这个功能常见于地址填写、配送区域设定等场景,用户可以从一个下拉菜单中逐级选择省、市、区,每一级的选择...

    linux kernel in a nutshell

    It acts as an interface between hardware and software, enabling developers to build robust and efficient systems. #### Building the Linux Kernel **1. Requirements for Building and Using the Kernel*...

    a project model for the FreeBSD Project.7z

    The FreeBSD release tree 4-3. The overall development model 5-1. Overview of official hats 6-1. Process summary: adding a new committer 6-2. Process summary: removing a committer 6-3. Process summary...

    保护环境的英语句子.docx

    - Simple acts like fixing leaks, using water-efficient appliances, and being mindful of water usage can make a significant difference. ### 四、Conclusion 1. **Long-Term Commitment** - We should ...

    Object-Oriented Analysis and Design 第六章

    - Adapter pattern allows objects with incompatible interfaces to work together by creating an adapter object that acts as a mediator. - Bridge pattern decouples an abstraction from its implementation,...

    servlet2.4doc

    Overview Package Class Tree Deprecated Index Help PREV NEXT FRAMES NO FRAMES A B C D E F G H I J L P R S U V -------------------------------------------------------------------------------- A ...

    VB编程资源大全(英文源码 控件)

    &lt;END&gt;&lt;br&gt;46,FldrView.zip The Folderview ActiveX Control mimics the behaviour of the Windows Explorer Treeview showing the tree structure of the files and folders and other items in the shell's ...

    中考英语考纲重点词汇用法复习总结.doc

    例如:He acts as our team leader and organizes activities actively. 9. **actual**: 形容词,真实的;**actually**: 副词,实际上。例如:The actual situation is quite different from what we expected; she...

    VB编程资源大全(英文源码 控制)

    1.x/6.0 (Java) &lt;END&gt;&lt;br&gt;6 , ocxex.zip "This is a quick example I made to show you how to use Events and properties in a OCX."&lt;END&gt;&lt;br&gt;7 , news.exe This control aids as a complete Newsgroup ...

Global site tag (gtag.js) - Google Analytics