-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathREADME
More file actions
50 lines (32 loc) · 1.08 KB
/
Copy pathREADME
File metadata and controls
50 lines (32 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
TreeSelect
==========
This plugin adds a few new methods to form-option helpers;
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
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