I am super new to rails and I was wondering how could I DRY this
<%- for page in @pages -%>
- <%= 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 } %>
<%- if page.children -%>
<%- for subpage in page.children -%>
-
<%= 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 } %>
<%- end -%>
<%- end -%>
<%- end -%>
Vincent, maybe I’m being dense here, but I’m not sure where you’re
repeating
yourself.
On 5/9/07, Vincent F. [email protected] wrote:
=> ‘add_sub’, :id => page.id } %>
<%- end -%>
<%- end -%>
–
Terry (TAD) Donaghe
http://tadspot.tumblr.com
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 F. [email protected] wrote:
On 5/9/07, Vincent F. < [email protected]
<%= link_to_remote (image_tag(‘add’)), :url => {
<%= link_to_remote (image_tag(‘delete’)), :url
–
Terry (TAD) Donaghe
http://tadspot.tumblr.com
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.
On May 9, 8:56 pm, Vincent F. [email protected] wrote:
<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:
<%= render :partial => 'page', :collection => @pages %>
and then _page.rhtml would be:
<%= 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 } %>
<%= render :partial => ‘subpage’, :collection => page.children if
page.children %>
and finally _subpage.rhtml would be:
<%= 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 } %>
More files, but each one is simple. Just food for thought.
Jeff