Hi Michel,
thanks for your response. The code that I have now can be used to set a
parent of an agent if the parent is not in the full_set of the agent.
Otherwise it would be an impossible move.
I just want to make an agent that has a parent now, make it a an agent with
root level is 0. So actually it is about how to delete a parent from an
agent and in fact making the agent a root node?
If I know the answer to that question then I can probably put something
together in my view to detach a parent from an agent.
Kind regards,
Mark
--------- Original Message --------
From: betternestedset-talk at rubyforge.org
To: betternestedset-talk at rubyforge.org <betternestedset-talk at
rubyforge.org>
Subject: Re: [Betternestedset-talk] Question about selecting a parent
Date: 20/03/07 23:47
> Hi,
>
> I see two possible solutions.
>
> Le 20 mars 07, ? 22:15, Mark Noten a ?crit :
> > I''m using the collection_select helper method in the
partial
> > _form.rhtml
> > that is used in the edit.rhtml. When I edit an agent I want to be
able> > to select a manager or no manager at all. In use the additional
:prompt> > option like this:
> >
> > <p><label
for="agent_parent_id">Manager</label><br/>> > <%= collection_select("agent",
"parent_id",
@agents, :id, :full_name,> > {:prompt => "Select manager..."}, {:style
=>
"width: 150px"})
%></p>>
> You could use select instead of collection_select and add your prompt
> associated with root:
>
> <%= select(''agent'', ''parent_id'',
@agents.inject([[Agent.root.id,
> ''Select one...'']]){|all, an_agent| [[an_agent.id,
> an_agent.full_name]]}) %>
>
> so your blank value would match the root of the tree and your node
> would be moved to be a level one child. (is it what you want ?)
>
> > The older Rails version always displayed the extra :prompt option.
I
> > use
> > the following code after the save in my update action:
> >
> > def update
> > @agent = Agent.find(params[:id])
> > if @agent.update_attributes(params[:agent])
> > @agent.move_to_child_of(params[:agent][:parent_id])
> > ...
> > end
>
> Second solution: test for empty parent_id here
>
> def update
> @agent = Agent.find(params[:id])
> if @agent.update_attributes(params[:agent]) and
> !params[:agent][:parent_id].empty?
> @agent.move_to_child_of(params[:agent][:parent_id])
>
> ;-)
>
> Jean-Christophe Michel
> --
> symetrie.com
>
> Better Nested Set for rails:
> http://opensource.symetrie.com/trac/better_nested_set
>
> _______________________________________________
> Betternestedset-talk mailing list
> Betternestedset-talk at rubyforge.org
> http://rubyforge.org/mailman/listinfo/betternestedset-talk
>
>
________________________________________________
Message sent using UebiMiau 2.7.10