没有任何数据可供显示
开源项目社区 | 当前位置 : |
|
www.trustie.net/open_source_projects | 主页 > 开源项目社区 > ajax-tree |
ajax-tree
|
0 | 0 | 11 |
贡献者 | 讨论 | 代码提交 |
Ajax TreeIntroductionThis is a helper plugin to generate ajax based tree structure (two level). It can be used for two models having n:m or 1:n relationship between them. A leaf from any branch can be dragged and dropped in another branch. A scaffolding arrangement is also done to create a new branch, add leaf etc.
For example:
class Category < ActiveRecord::Base
has_many :articles
validates_presence_of :name
endclass Article < ActiveRecord::Base
belongs_to :categories
validates_presence_of :name
endInstallationruby script/plugin install http://ajax-tree.googlecode.com/svn/trunk/ajax_tree/Here we take the previous example of Category and Article models. Generate the ajax controller for the two models.
Usageruby script/generate controller model1 model2Exampleruby script/generate home category articleCopy static filesCopy add.png, delete.png from /vendor/plugins/ajax_tree/ directory to /public/images directory.
Copy ajax_tree.css file from /vendor/plugins/ajax_tree/ directory to /public/stylesheets/ directory.
Include css in your application layoutCall the helpersSpecify model names for branch model and leaf model in /views/home/show_ajax_tree.rhtml partial.
'category',:leaf => 'article'})%>Then, call this partial in any rhtml, where you want to display the ajax tree. In this case, we have done it in /views/home/index.rhtml
home_controller.rb (Generated automatically)
class HomeController < ApplicationController
def index
@branches = Category.find(:all)
end
:
:
:
endindex.rhtml
'show_ajax_tree' %>Example Output
Credits:Ripan Kumar Sylvain Bonfils Vincent Spehner Anup Narkhede ThinkDRY.com