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> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Vincent, maybe I''m being dense here, but I''m not sure where you''re repeating yourself. On 5/9/07, Vincent Franco <vincent-franco-Wuw85uim5zDR7s880joybQ@public.gmane.org> wrote:> > > 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 (TAD) Donaghe http://tadspot.tumblr.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
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:> Vincent, maybe I''m being dense here, but I''m not sure where you''re > repeating yourself. > > On 5/9/07, *Vincent Franco* < vincent-franco-Wuw85uim5zDR7s880joybQ@public.gmane.org > <mailto:vincent-franco-Wuw85uim5zDR7s880joybQ@public.gmane.org>> wrote: > > > 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 <http://page.id>} %> > <%= link_to_remote (image_tag(''add'')), :url => { > :action > => ''add_sub'', :id => page.id <http://page.id> } %> > </li> > <%- if page.children -%> > <ul> > <%- for subpage in page.children -%> > <li id="page_<%= subpage.id <http://subpage.id> %>"> > <%= link_to_remote subpage.title, :url => { > :action > => "view_page", :id => subpage.id <http://subpage.id>} %> > <%= link_to_remote (image_tag(''delete'')), :url > => { > :action => ''delete_page'', :id => subpage.id <http://subpage.id> > } %></li> > <%- end -%> > </ul> > <%- end -%> > <%- end -%> > </ul> > > > > > > > > -- > Terry (TAD) Donaghe > http://tadspot.tumblr.com > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Vincent, while I agree that you have some logic in your view, I''m not sure that it''s too much. I don''t see where you''d need to pare something down, but maybe someone else will. It looks fine to me. On 5/9/07, Vincent Franco <vincent-franco-Wuw85uim5zDR7s880joybQ@public.gmane.org> wrote:> > > 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: > > Vincent, maybe I''m being dense here, but I''m not sure where you''re > > repeating yourself. > > > > On 5/9/07, *Vincent Franco* < vincent-franco-Wuw85uim5zDR7s880joybQ@public.gmane.org > > <mailto:vincent-franco-Wuw85uim5zDR7s880joybQ@public.gmane.org>> wrote: > > > > > > 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 <http://page.id>} %> > > <%= link_to_remote (image_tag(''add'')), :url => { > > :action > > => ''add_sub'', :id => page.id <http://page.id> } %> > > </li> > > <%- if page.children -%> > > <ul> > > <%- for subpage in page.children -%> > > <li id="page_<%= subpage.id <http://subpage.id> %>"> > > <%= link_to_remote subpage.title, :url => { > > :action > > => "view_page", :id => subpage.id <http://subpage.id>} %> > > <%= link_to_remote (image_tag(''delete'')), :url > > => { > > :action => ''delete_page'', :id => subpage.id <http://subpage.id> > > } %></li> > > <%- end -%> > > </ul> > > <%- end -%> > > <%- end -%> > > </ul> > > > > > > > > > > > > > > > > -- > > Terry (TAD) Donaghe > > http://tadspot.tumblr.com > > > > > > > >-- Terry (TAD) Donaghe http://tadspot.tumblr.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On May 9, 8:56 pm, Vincent Franco <vincent-fra...-Wuw85uim5zDR7s880joybQ@public.gmane.org> wrote:> 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>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 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---