I''m new to RoR and am working on the development of a small project management application just to get my hands wet. Consider the following model entities: class Site < ARB has_many :projects end class Project < ARB belongs_to :site has_many :tasks end class Task < ARB belongs_to :project belongs_to :user end class User < ARB has_many :tasks end How can I display all sites and their "child" projects without making my view totally disgusting (or my controller for that matter)? For example: class site_controller < ApplicationController def list @sites = Site.find(:all) end end site/list.rhtml #view <% @sites.each do |site| projects = site.projects.find(:all) %> <%= site.name %> <% projects.each do |project| %> <%= project.name %> <% end %> <% end %> That''s obviously not the way to do it. Suggestions? -- 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 -~----------~----~----~----~------~----~------~--~---
You need to use partial templates: site/list.rhtml #view <%= render(:partial => "site", :collection => @sites) %> site/_site.rhtml # partial template to render each site <%= site.name %> <%= render(:partial => "project", :collection => site.projects.find(:all)) %> site/_project.rhtml # partial template to render each project <%= project.name %> HTH :) -- 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 -~----------~----~----~----~------~----~------~--~---