[Betternestedset-talk] Question about selecting a parent

Mark.noten mark.noten at itfc.be
Wed Mar 21 06:50:07 EDT 2007


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 :
> &gt; I'm using the collection_select helper method in the partial 
> &gt; _form.rhtml
> &gt; that is used in the edit.rhtml. When I edit an agent I want to be
able
> &gt; to select a manager or no manager at all. In use the additional
:prompt
> &gt; option like this:
> &gt;
> &gt; &lt;p&gt;&lt;label
for=&quot;agent_parent_id&quot;&gt;Manager&lt;/label&gt;&lt;br/&gt;
> &gt; &lt;%= collection_select(&quot;agent&quot;, &quot;parent_id&quot;,
@agents, :id, :full_name,
> &gt; {:prompt =&gt; &quot;Select manager...&quot;}, {:style =&gt;
&quot;width: 150px&quot;}) %&gt;&lt;/p&gt;
> 
> You could use select instead of collection_select and add your prompt 
> associated with root:
> 
> &lt;%= select('agent', 'parent_id', @agents.inject([[Agent.root.id, 
> 'Select one...']]){|all, an_agent| [[an_agent.id, 
> an_agent.full_name]]}) %&gt;
> 
> 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 ?)
> 
> &gt; The older Rails version always displayed the extra :prompt option. I 
> &gt; use
> &gt; the following code after the save in my update action:
> &gt;
> &gt; def update
> &gt;     @agent = Agent.find(params[:id])
> &gt;     if @agent.update_attributes(params[:agent])
> &gt;       @agent.move_to_child_of(params[:agent][:parent_id])
> &gt; ...
> &gt; 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




More information about the Betternestedset-talk mailing list