I''ve been stumbling on the tut at oriontransfer
(http://wiki.oriontransfer.co.nz/main/show/SortableTree)
I''ve got it working in a one dimensional list and I''ve got the
drag and
drop working on children, but as can''t get it to save the tree.
Here''s my view:
<h2>Menu Prototype 2</h2>
<%= flash[:notice] %>
<ul id="menu">
<% @navigation.each do |link| %>
<li class="edit_link level<%= link.parent_id %>"
id="_<%= link.id.to_s
%>">
<%= link.name %>
<ul class="edit_list">
<% link.children.each do |child| %>
<li class="edit_link level<%= child.parent_id %>"
id="_<%=
child.id.to_s %>">
<%= child.name %>
</li>
<% end -%>
</ul>
</li>
<% end -%>
</ul>
<%= sortable_element ''menu'',
:url => { :action => "sort", :id => @navigation },
:complete => visual_effect(:highlight, ''menu''), :tree =>
true
%>
<div id="debug">
</div>
Here''s the action:
def change_hierarchy
change_links params[:menu]
end
def change_links (links_hash)
parent_id = links_hash[:id] || Link.root.id
links_hash.each do |key, value|
next if key == "id"
link = Link.find (value[:id])
link.display_order = key
link.parent_id = parent_id
link.save
change_links value
end
end
Does anyone have a clue what''s my mess?
--
Posted via http://www.ruby-forum.com/.
Victor manuel Martin-romo beni...
2011-Jan-24 11:54 UTC
Re: sortable acts_as_tree with heirarchy
Hola,
He echo una adaptacion de tu codigo, a mí me funciona:
Mi condicion de categoria principal: (category.parent_id == nil)
Mi partial(_categories.html.erb):
<ul id="categories" style="list-style:none;">
<% @categories.all(:order => "show_order asc").each do
|category| %>
<% content_tag_for :li, category do %>
<span class="handle"><%= image_tag "drag.png"
%></span>
<%= link_to category.name, blog_category_path(@blog.permalink,
category.permalink)%> (<%= category.posts.size%>)
<ul class="<%= category.children.size > 0 ? "" :
"blog_category"
%>" style="list-style:none;">
<% category.children.all(:order => "show_order
asc").each do
|sub_category| %>
<% content_tag_for :li, sub_category do %>
<span class="handle"><%= image_tag
"drag.png"%> </span>
<%= link_to sub_category.name,
blog_category_path(@blog.permalink, sub_category.permalink)%>
(<%= sub_category.posts.size%>)
<% end %>
<% end %>
</ul>
<% end %>
<% end %>
</ul>
<%= sortable_element ''categories'', :url =>
sort_blog_categories_path(@blog.permalink),:complete =>
visual_effect(:highlight, ''categories''), :handle =>
"handle", :tree =>
:true, :update => "nav_zone" %>
Mi controlador:
def sort
i_sort params[:categories]
@categories = @blog.categories.root
render :partial => "categories/categories.html.erb"
end
def i_sort(categories_hash )
parent_id = categories_hash[:id] || nil
puts categories_hash.to_a.to_s rescue puts categories_hash.to_s
categories_hash.each do |key, value|
if key != "id"
category = Category.find(value[:id].to_i)
category.show_order = key
category.parent_id = parent_id
category.save
i_sort(value)
end
end
end
Suerte.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.