Nik
2008-Jun-20 16:29 UTC
Can ''tasks'' belong to ''user'' and ''project'' at the same time?
Hello All! I have ''project'' and ''task'' model that is set to belongs_to ''user'', and ''user'' has_many ''projects'' and ''task'', and I have the config/ routes.db using map.resource :users, :has_many [:projects, :tasks] I can use all seven actions in the users controllers to manipulate projects, for instance, http://localhost:3000/users/1/projects renders the ProjectController''s index action with index.html.erb showing all projects of user 1. Same goes on for tasks. If I go to http://localhost:3000/users/1/tasks the browser shows up the index list of all tasks belonging to this user 1 Would you be kind enough to show me some hints to realizing a functionality that when I go to http://localhost:3000/users/1/projects/1/tasks to see all the tasks in project 1 of user 1. Thank You Very Much! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Robert Walker
2008-Jun-20 18:03 UTC
Re: Can ''tasks'' belong to ''user'' and ''project'' at the same time?
> http://localhost:3000/users/1/projects/1/tasksI think you are mis-interrupting the meaning of that URI. users/1/ projects/1/tasks would mean "Collection of tasks for project with id == 1 under the user with id == 1." In other words "users/1/project" is the collection of projects for a user with id == 1. Then projects/1/tasks is the collection of tasks for a project with id == 1. So if projects/1 is not associated to users/1 then users/1/projects/1/tasks would return an empty collection because users/1/projects/1 would not be found. This would mean your database schema would be: User: has_many :projects Project: has_many :tasks Project: belongs_to :user Task: belongs_to :project Which is not the structure of the schema you presented. On Jun 20, 12:29 pm, Nik <NiKS...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello All! > > I have ''project'' and ''task'' model that is set to belongs_to ''user'', > and ''user'' has_many ''projects'' and ''task'', and I have the config/ > routes.db using > > map.resource :users, :has_many [:projects, :tasks] > > I can use all seven actions in the users controllers to manipulate > projects, for instance, > > http://localhost:3000/users/1/projects > > renders the ProjectController''s index action with index.html.erb > showing all projects of user 1. > > Same goes on for tasks. If I go to > > http://localhost:3000/users/1/tasks > > the browser shows up the index list of all tasks belonging to this > user 1 > > Would you be kind enough to show me some hints to realizing a > functionality that when I go to > > http://localhost:3000/users/1/projects/1/tasks > > to see all the tasks in project 1 of user 1. > > Thank You Very Much!--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nik
2008-Jun-21 00:00 UTC
Re: Can ''tasks'' belong to ''user'' and ''project'' at the same time?
Hi Robert, Let me make sure I am getting this right: http://dns/users/1/projects/1/tasks returns the collection of tasks with the criteria requiring that these tasks belong to project 1 and these tasks belong to user 1 So if we put it in context, will these url find the following sentence: I want to see Nik''s Cleaning Garage tasks where Nik is the user, Cleaning Garage is HIS project, the tasks are the get the oil stains and buy more shelves and etc. Thank you so much for your time. Nik On Jun 20, 8:03 pm, Robert Walker <r0b3rt4...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> >http://localhost:3000/users/1/projects/1/tasks > > I think you are mis-interrupting the meaning of that URI. users/1/ > projects/1/tasks would mean "Collection of tasks forprojectwith id > == 1 under theuserwith id == 1." > > In other words "users/1/project" is the collection of projects for auserwith id == 1. Then projects/1/tasks is the collection of tasks > for aprojectwith id == 1. So if projects/1 is not associated to > users/1 then users/1/projects/1/tasks would return an empty collection > because users/1/projects/1 would not be found. > > This would mean your database schema would be: > > User: has_many :projectsProject: has_many :tasks > > Project: belongs_to :user > > Task: belongs_to :project > > Which is not the structure of the schema you presented. > > On Jun 20, 12:29 pm, Nik <NiKS...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hello All! > > > I have ''project'' and ''task'' model that is set to belongs_to ''user'', > > and ''user'' has_many ''projects'' and ''task'', and I have the config/ > > routes.db using > > > map.resource :users, :has_many [:projects, :tasks] > > > I can use all seven actions in the users controllers to manipulate > > projects, for instance, > > >http://localhost:3000/users/1/projects > > > renders the ProjectController''s index action with index.html.erb > > showing all projects ofuser1. > > > Same goes on for tasks. If I go to > > >http://localhost:3000/users/1/tasks > > > the browser shows up the index list of all tasks belonging to this > >user1 > > > Would you be kind enough to show me some hints to realizing a > > functionality that when I go to > > >http://localhost:3000/users/1/projects/1/tasks > > > to see all the tasks inproject1 ofuser1. > > > Thank You Very Much!--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---