I bet this this look better in a pastie. Kind of hard to see the
format.

On Aug 2, 2:39 pm, Owen Dall <[email protected]> wrote:
> Wow - nice example!
> -Owen
>
> On Mon, Aug 2, 2010 at 5:02 PM, Simeon Theobald
> <[email protected]>wrote:
>
>
>
>
>
> > Thanks Chuck - I haven't had a chance to try this out yet, but greatly
> > appreciate the effort you've gone to in fitting an example to my use case.
>
> > I'll let you know how it works out.
>
> > Simeon.
>
> > On Mon, Aug 2, 2010 at 2:44 AM, <[email protected]> wrote:
>
> >> After I wrote the acts_as_tree recipe, I wrote another tag definition that
> >> iterates over an acts_as_tree model and displays the cards of an associated
> >> has_many model.  This will not work precisely the way you want for your use
> >> case, but might spur some ideas.
>
> >> Example:
>
> >> class Question < ActiveRecord::Base
> >>   hobo_model
> >>   fields do
> >>     name :string
> >>     parent_id :integer
> >>   end
>
> >>   has_many :answers
> >>   belongs_to :answer
> >>   acts_as_tree
> >> end
>
> >> class Answer < ActiveRecord::Base
> >>   hobo_model
> >>   fields do
> >>     name : string
> >>   end
> >>   belongs_to :question
> >>   has_one :another_question_to_ask, :class_name => 'question'
> >> end
>
> >> In application.dryml:
>
> >> <extend tag="index-page" for="Question">
>
> >>     <old-index-page merge>
>
> >>         <after-new-link:><p><br/>Click a question to view
> >> answers.</p></after-new-link:>
>
> >>         <!-- Remove pager control -->
>
> >>         <top-page-nav: replace />
>
> >>         <collection: replace>
>
> >>             <hierarchical-collection with="&Question.all" to="answers">
>
> >>                 <append-close-button:>
>
> >>                     <a:answers action="new"
> >> if="&can_create?(this.answers)">
>
> >>                         <ht key="answers.actions.new">
>
> >>                             New Answer
>
> >>                         </ht>
>
> >>                     </a:answers>
>
> >>                 </append-close-button:>
>
> >>             </hierarchical-collection>
>
> >>         </collection:>
>
> >>         <!-- Remove pager control -->
>
> >>         <bottom-page-nav: replace />
>
> >>     </old-index-page>
>
> >> </extend>
>
> >> <def tag="hierarchical-collection" attrs="to">
>
> >>     <%
>
> >>         def tree_h(acts_as_tree_set, init=true, &block)
>
> >>             @@level = 1 if init
>
> >>             if acts_as_tree_set.size > 0
>
> >>                 acts_as_tree_set.collect do |item| %>
>
> >>                     <do with="&item"> <%
>
> >>                         next if item.parent_id && init
>
> >>                         @@level += 1
>
> >>                         yield item
>
> >>                         tree_h(item.children, false, &block) if
> >> item.children.size > 0
>
> >>                         @@level -= 1 %>
>
> >>                     </do> <%
>
> >>                 end
>
> >>             else
>
> >>                 %>(none)<%
>
> >>             end
>
> >>         end
>
> >>         tree_h(this, true) { |item|
>
> >>             item_for = to.nil? ? item : item.send(to) %>
>
> >>             <%= "<h#{@@level}>" %>
>
> >>             <a href="#"
> >> onclick="Effect.BlindDown('hierarchy-collection-#{item.typed_id.gsub(':','-
> >>  ')}');
> >> return false;" param="hierarchy-link">
>
> >>             <%= item.name + ("&nbsp;(#{item_for.count})" if
> >> item_for.respond_to?('count')) %>
>
> >>             </a>
>
> >>             <%= "</h#{@@level}" %><%
>
> >>             if item_for.respond_to?('count') %>
>
> >>                 <div
> >> id="hierarchy-collection-#{item.typed_id.gsub(':','-')}" style="display:
> >> none" param="hierarchy-section">
>
> >>                     <div class="close-button" param="close-button">
>
> >>                         <a href="#"
> >> onclick="$('hierarchy-collection-#{item.typed_id.gsub(':','-')}').hide();
> >> return false;">close</a>
>
> >>                     </div>
>
> >>                     <collection with="&item_for" param="items" />
>
> >>                 </div><%
>
> >>             end
>
> >>         }
>
> >>     %>
>
> >> </def>
>
> >> --- On *Sat, 7/31/10, Simeon Theobald <[email protected]>* wrote:
>
> >> From: Simeon Theobald <[email protected]>
> >> Subject: Re: [Hobo Users] Multiple models in one tree?
> >> To: [email protected]
> >> Date: Saturday, July 31, 2010, 12:19 AM
>
> >> Okay - a rough outline:
>
> >> A question has many potential answers. Each answer can lead to a number of
> >> questions. An example would be:
>
> >> +Would you like Coffee or Tea?   [Question]
> >> - Coffee     [Answer]
> >>    +De-Caff or Regular?    [Question]
> >>      -De-Caff   [Answer]
> >>      -Regular   [Answer]
> >>      +Moccona or Nescafe    [Question]
> >> -Tea         [Answer]
>
> >> I can't see that recursive nesting of two trees should be a problem given
> >> that we can pass in the "parentid" (which incidentally I need to figure out
> >> how to specify differently), the problem at the moment is that I can't see 
> >> a
> >> way to pass the current "id" to the alternate model's tree as a "parentid".
>
> >> I'd eventually like to include links to add "children", or edit/remove the
> >> current node. That functionality further complicates things in that it will
> >> involve manipulating records in the intermediary tables as well as the leaf
> >> level. Nesting sure messes with your frame of reference!
>
> >> First things first though, I need to get a tree out somehow..
>
> >> On Sat, Jul 31, 2010 at 12:43 PM, Chuck Benedict <
> >> [email protected] 
> >> <http://mc/[email protected]>>wrote:
>
> >> Give me a use case and I'll be glad to add my $0.02
>
> >> Sent from my iPhone
>
> >> On Jul 30, 2010, at 5:02 AM, Simeon 
> >> <[email protected]<http://mc/[email protected]>>
> >> wrote:
>
> >> The learning curve gets steep in a hurry around these parts!
>
> >> The "Hierarchies - Using acts_as_tree" recipe deals nicely with a self
> >> referencing model (category belongs to category) but it takes on the
> >> context of the model containing the call. I have yet to find reference
> >> to a similar solution involving multiple (nested) models.
>
> >> Is it possible, and how would I go about starting to figure it out?
>
> >> Thanks for your thoughts!
>
> >>  --
> >> You received this message because you are subscribed to the Google Groups
> >> "Hobo Users" group.
> >> To post to this group, send email to [email protected].
> >> To unsubscribe from this group, send email to
> >> [email protected]<hobousers%2bunsubscr...@googlegroups
> >>  .com>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/hobousers?hl=en.
>
> >>  --
> >> You received this message because you are subscribed to the Google Groups
> >> "Hobo Users" group.
> >> To post to this group, send email to [email protected].
> >> To unsubscribe from this group, send email to
> >> [email protected]<hobousers%2bunsubscr...@googlegroups
> >>  .com>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/hobousers?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Hobo Users" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<hobousers%2bunsubscr...@googlegroups 
> > .com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/hobousers?hl=en.
>
> --
> - Owen
>
> Owen Dall, Chief Systems Architect
> Barquin International
> Cell: 410-991-0811

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to