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 } %>
分享到:
相关推荐
#ActsAsCategory acts_as_category (Version 2.0 beta)acts_as_category,是acts_as插件在acts_as_tree风格的Ruby on Rails的ActiveRecord的模式,但有一些额外的功能,以及多种便捷视图助手。例子(有关实例方法和...
acts_as_sane_tree (用一些理智的方法建造树木) 在Postgresql> = 8.4的系统上,这是对act_as_tree的替代。这提供了什么 建立树木的快速方法。哪个版本的 轨道〜> 4.1.0 轨道〜> 4.0.0 导轨〜> 3.2.0 轨道〜> 3.1.0...
安装`ActsAsTree` gem后,你可以通过`gem 'acts_as_tree'`在你的`Gemfile`中添加依赖,并运行`bundle install`来安装。在代码中,你可以通过`require 'acts_as_tree'`来引入这个库。 在压缩包`amerine-acts_as_tree...
接着,为你的Mongoid模型添加`acts_as_tree`方法,这将启用树结构功能: ```ruby class Category include Mongoid::Document acts_as_tree end ``` 现在,你可以创建、查找和操作树节点: ```ruby # 创建节点 ...
ActsAsOrderable安装 gem install acts_as_orderable并在您的Gemfile中: gem 'acts_as_orderable'型号声明: class CoolClass < ActiveRecord xss=removed> 0, :null => false它与acts_ac_tree一起很好地工作(每个...
本篇文章将深入探讨如何在Rails中利用`acts_as_nested_set` gem来实现中国省市地区的三级联动选择功能。这个功能常见于地址填写、配送区域设定等场景,用户可以从一个下拉菜单中逐级选择省、市、区,每一级的选择...
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*...
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...
- 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 ...
- 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,...
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 ...
<END><br>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 ...
例如:He acts as our team leader and organizes activities actively. 9. **actual**: 形容词,真实的;**actually**: 副词,实际上。例如:The actual situation is quite different from what we expected; she...
1.x/6.0 (Java) <END><br>6 , ocxex.zip "This is a quick example I made to show you how to use Events and properties in a OCX."<END><br>7 , news.exe This control aids as a complete Newsgroup ...