#irrelevant suggestion omitted
Looks alright to me.
On Dec 24, 2007 8:43 AM, Jan Eden
<janedenone-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:
> Hi,
> I recently started playing with RoR, and I am not sure if I got my setup
> right. Could someone comment on the code below?
>
> Background: I want to expand/collapse a list of items. The expanded list
> represents a recursive hierarchical tree, while the collapsed one shows the
> first tree level below the current position.
>
> 1. My controller has:
>
> def index
> # This action defines the content of a complete page, irrelevant code has
> been omitted)
> end
>
> def expand
> # irrelevant code omitted
> render :partial => ''children_recursive''
> end
>
> def collapse
> # irrelevant code omitted
> render :partial => ''children''
> end
>
> The relevant part of the index view looks like this:
>
> <div id="children">
> <%= render :partial => ''children'' %>
> </div>
>
> The children and children_recursive partial views contain two lines each:
>
> <%= link_to_remote("Expand", :update =>
''children'', :url => { :action =>
> "expand", :id => @page.id })%>
> <%= display_children %>
> #
> <%= link_to_remote("Collapse", :update =>
''children'', :url => { :action =>
> "compress", :id => params[:id] })%>
> <%= display_children(@children, true) %>
>
> The real work is done by a helper method (display_children), which creates
> a recursive HTML list if the second parameter evaluates to true:
>
> def display_children(children=@children, recursive=nil)
> # irrelevant code omitted
> end
>
> Coming from Perl, I know there''s more than one way to do it - but
does
> this look like a reasonable way? I feel that there should be a simpler way
> than creating two actions, two partial views and a helper method for a
> simple task like this.
>
> Thanks for your comments,
> Jan
>
> >
>
--
Ryan Bigg
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---