I currently have some ugly loops code in my view that I''m trying to clean up. I''m not sure where to move this code in order to get it all to work. The view code looks like this. <% for a in @model.a %> <% @pa = PA.find(a.A_ID) %> <% @p = P.find(@pa.P_ID)%> <% @pm = PM.find_by_P_ID(@pa.P_ID) %> <%# Sample Output %> <%=h @pa.P_ID %><br/> <%=h @p.Address_1 %> <%=h @pm.To %> <% end %> The idea is that I first look up the value of "a". This is in my controller in the show definition. Then I want to be able to take the value of "a" and look in my "PA" table to find an ID. Then I want to take that value to look up values in 2 other tables to produce the output. Where should I put the queries that are in my view and how would that code look since I need to use the value that''s in "a"? Thanks! -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
> I currently have some ugly loops code in my view that I''m trying to > clean up. I''m not sure where to move this code in order to get it all to > work. > > The view code looks like this. > > <% for a in @model.a %> > > <% @pa = PA.find(a.A_ID) %> > <% @p = P.find(@pa.P_ID)%> > <% @pm = PM.find_by_P_ID(@pa.P_ID) %> > > <%# Sample Output %> > <%=h @pa.P_ID %><br/> > <%=h @p.Address_1 %> > <%=h @pm.To %>Why can''t you just reference them as... a.pa.P_ID a.p.address_1 a.pm.To ... in the view? Assuming your associations are setup that seems like the logicial thing to me. -p> > <% end %> > > > The idea is that I first look up the value of "a". This is in my > controller in the show definition. > > Then I want to be able to take the value of "a" and look in my "PA" > table to find an ID. Then I want to take that value to look up values > in 2 other tables to produce the output. > > Where should I put the queries that are in my view and how would that > code look since I need to use the value that''s in "a"?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---