Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

58 lines (40 sloc) 1.345 kb
TreeSelect
==========
This plugin adds a few new methods to form-option helpers;
Requires acts_as_tree gem (plugin).
Works with Rails 3.
options_from_tree_collection_for_select(collection, value_method, text_method, selected = nil)
This method works like the options_from_collection_for_select, however, it recurses through the childelements, indenting them with characters on the left;
level 1
----- level 1 1
----- level 1 2
---------- level 1 2 1
---------- level 1 2 2
----- level 1 3
tree_select(method, collection, value_method, text_method, options = {}, html_options = {})
This method allows you to put a tree_select tag in your forms.
Example
=======
Create an acts_as_tree model, e.g;
class Category < ActiveRecord::Base
acts_as_tree
end
Create another class that should link somewhere to the tree, e.g.;
class Item < ActiveRecord::Base
validates_presence_of :category_id, :name
end
Change your form;
<% form_for(@item) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :category_id %><br />
<%= f.tree_select :category_id, Category.roots, :id, :name, :include_blank => true %>
</p>
...
<% end %>
Install
=======
./script/plugin install git://github.com/stijnster/tree_select.git
In Rails 3 add:
gem 'tree_select', :git => 'git://github.com:jeznet/tree_select.git'
to Gemfile and run: bunlde install
Jump to Line
Something went wrong with that request. Please try again.