Best way to DRY this?

I am super new to rails and I was wondering how could I DRY this

<ul>
    <%- for page in @pages -%>
        <li><%= link_to_remote page.title, :url => { :action => "view_page", :id => page.id} %>
                <%= link_to_remote (image_tag('add')), :url => { :action => 'add_sub', :id => page.id } %>
                                 </li>
        <%- if page.children -%>
            <ul>
            <%- for subpage in page.children -%>
                <li id="page_<%= subpage.id %>">
                    <%= link_to_remote subpage.title, :url => { :action => "view_page", :id => subpage.id} %>
                    <%= link_to_remote (image_tag('delete')), :url => { :action => 'delete_page', :id => subpage.id } %></li>
            <%- end -%>
            </ul>
        <%- end -%>
    <%- end -%>
</ul>

Terry, Sorry I used the wrong wording. I think what I meant to say was I
seem to have alot of logic in my view I would like a more elegant way to
achieve what I have here. a helper? im am not sure.

Terry Donaghe wrote:

Looks pretty good, but if things feel ugly, you might moving the
inside of each loop intto partials:

So your whole template is reduced to:

<ul>
  <%= render :partial => 'page', :collection => @pages %>
</ul>

and then _page.rhtml would be:

<li><%= link_to_remote page.title, :url => { :action =>
"view_page", :id => page.id} %>
      <%= link_to_remote (image_tag('add')), :url => { :action =>
'add_sub', :id => page.id } %>
</li>

<%= render :partial => 'subpage', :collection => page.children if
page.children %>

and finally _subpage.rhtml would be:

<li id="page_<%= subpage.id %>">
   <%= link_to_remote subpage.title, :url => { :action =>
"view_page", :id => subpage.id} %>
   <%= link_to_remote (image_tag('delete')), :url => {:action =>
'delete_page', :id => subpage.id } %>
</li>

More files, but each one is simple. Just food for thought.

Jeff
softiesonrails.com