Can''t think it through... list belongs_to :projects I can get a size of items in a list for a project> project.lists.sizelist can be marked "done" how do I get a size for list not marked done? so if I have three unfinished items in a list of eight i''d like to see fix project 3 tasks not fix project 8 tasks ---------------------------------- project_controller def list @projects_not_done = Project.find(:all, :conditions => "completed_at is null") end ---------------------------------- view... <h1>listing projects</h1> <ul> <% for project in @projects_not_done %> <li> <%= link_to project.title, :action => ''show'', :id => project %> - <%= pluralize(project.lists.size, "task") %> </li> <% end %> </ul> ---------------------------------- thanks john --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Can''t think it through... > list belongs_to :projects > > I can get a size of items in a list for a project >> project.lists.size > > list can be marked "done" > how do I get a size for list not marked done?In your Project model add: has_many :unfinished_lists, :class_name => ''List'', :conditions => ''completed_at is null'' Then use: project.unfinished_lists.size -philip> so if I have three unfinished items in a list of eight > i''d like to see > > fix project 3 tasks > > not > > fix project 8 tasks > > ---------------------------------- > project_controller > def list > @projects_not_done = Project.find(:all, :conditions => "completed_at is > null") > end > ---------------------------------- > > view... > <h1>listing projects</h1> > <ul> > <% for project in @projects_not_done %> > <li> > <%= link_to project.title, :action => ''show'', :id => project %> - > <%= pluralize(project.lists.size, "task") %> > </li> > <% end %> > </ul> > ---------------------------------- > > thanks > john > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Philiip, thank you. let me see if i understand this... has_many :lists makes the assumption that the class is list, i want everything and the name of this object is lists? i could say has_many :the_longest_name_possible, :class_name => ''List'' i would get the same results except i need to reference the_longest_name_possible? I''m going to try this and look back at my AWDR book because when i saw you response it looked familiar. thanks again. John On 1/4/07, Philip Hallstrom <rails-SUcgGwS4C16SUMMaM/qcSw@public.gmane.org> wrote:> > > Can''t think it through... > > list belongs_to :projects > > > > I can get a size of items in a list for a project > >> project.lists.size > > > > list can be marked "done" > > how do I get a size for list not marked done? > > In your Project model add: > > has_many :unfinished_lists, :class_name => ''List'', :conditions => > ''completed_at is null'' > > > Then use: > > project.unfinished_lists.size > > -philip > > > so if I have three unfinished items in a list of eight > > i''d like to see > > > > fix project 3 tasks > > > > not > > > > fix project 8 tasks > > > > ---------------------------------- > > project_controller > > def list > > @projects_not_done = Project.find(:all, :conditions => "completed_at is > > null") > > end > > ---------------------------------- > > > > view... > > <h1>listing projects</h1> > > <ul> > > <% for project in @projects_not_done %> > > <li> > > <%= link_to project.title, :action => ''show'', :id => project %> - > > <%= pluralize(project.lists.size, "task") %> > > </li> > > <% end %> > > </ul> > > ---------------------------------- > > > > thanks > > john > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---