How would I make an acts_as_tree (or acts_as_nested_set) model
editable? Anyone know any nifty rjs in-place tree editor? Or a
treeview js widget that is editable (and is or can be integrated into
Rails)?
Thanks,
- Mark.
How would I make an acts_as_tree (or acts_as_nested_set) model
editable? Anyone know any nifty rjs in-place tree editor? Or a
treeview js widget that is editable (and is or can be integrated into
Rails)?
Thanks,
On Nov 15, 2007 9:55 AM, Mark T. [email protected] wrote:
How would I make an acts_as_tree (or acts_as_nested_set) model
editable? Anyone know any nifty rjs in-place tree editor? Or a
treeview js widget that is editable (and is or can be integrated into
Rails)?
I use this drag and drop editor:
http://wiki.oriontransfer.co.nz/main/show/SortableTreeTutorial Sadly the
wiki for this software seems to get defaced regularly - but right now
that
page is still showing non-spam content.
Mark,
here is something I knocked up the other day. It allows navigation
and editing all on one screen, using ajax to do the updates and
navigate the select list. My plan is to integrate it into a redBox
popup for product categories. You may find some of it useful. The
select list part could be used in isolation for allocating the
category and the edit/add/delete fields included when editing
categories. this is still in early form, and there is room for
improvement. Perhaps it needs to be better crudded. But it works as
an example of a possible solution. Table has id, parent_id and name
fields. I havn’t added sort to it yet, but I probably will. For
clarity and brevity, I have removed the css formatting stuff that
makes it pretty, but you will get the idea.
class CategoryController < ApplicationController
def show
@category=Category.find_by_parent_id nil
end
def pick
if params[:id]
@category=Category.find params[:id]
elsif params[:new]
@category=Category.find params[:category_id]
@[email protected] :name=>params[:name]
@category.save
@category=@new_category # optional - to go to new category rather
than stay in current one
elsif params[:delete]
@category=Category.find params[:delete_id]
@[email protected]
[email protected]
@category=@parent if r
elsif params[:category_id]
@category=Category.find params[:category_id]
@category.update_attribute :name, params[:name]
else
@category=Category.find_by_parent_id(nil)
end
render :update do |page|
page.replace_html ‘pick_category’, :partial=>‘pick’
page.replace_html :prompt, :partial=>‘layouts/all_messages’
end
end
end
VIEWS:
Note 1. I particularly wanted to navigate the tree rather than
display the whole tree with all branches in the
select field so I have written the helpers to do that. You may prefer
to populate all branches, in which case there is example code on the
rails wiki.
Note 2. I don’t offer the delete option if the category has child
categories. You may prefer to allow deletion of the whole sub
branch.
hope this may be of some value
Tonypm
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs