jesusOmar
2010-Mar-25 03:47 UTC
Nested Models Projects :has_many Tasks and Tasks :has_many Notes
Hello everyone, I have 3 models that I am trying to link togheter: resources :projects :shallow => true do resources :tasks do resources :notes end end So most of it is working fine, but I can''t figure out how to create links between them. If I try this: link_to task.name, project_tasks_path(@project, task.id) I get the following URL: /projects/2/tasks.3 If I try this: link_to task.name, project_tasks_path(@project, @tasks) The error is even more cryptic. What I want is to have my /projects list all my projects. /projects/1 list all the tasks for that project and link to each specific task. / projects/1/tasks/2 will display all the notes attached to the tasks, and link to each note. /projects/1/tasks/2/notes/3 will be a specific note. Thanks. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Antonio Tapiador del Dujo
2010-Mar-26 08:30 UTC
Re: Nested Models Projects :has_many Tasks and Tasks :has_many Notes
Hi jesusOmar, first of all, let me tell you that this question should go to rubyonrails-talk group (http://groups.google.com/group/rubyonrails-talk). This one (rails-core) is intended to other topics, related with the development of Rails itself. As for your question, you have to write "task" in singular when you want to link to specific task, and not to the tasks list. link_to task.name, project_task_path(@project, task) You also should avoid using task.id, Rails does it for you, and maybe in the future you''ll link to the tasks using another param like a permalink. Cheers! El Jueves, 25 de Marzo de 2010 04:47:38 jesusOmar escribió:> Hello everyone, > > I have 3 models that I am trying to link togheter: > > resources :projects :shallow => true do > resources :tasks do > resources :notes > end > end > > So most of it is working fine, but I can''t figure out how to create > links between them. If I try this: > > link_to task.name, project_tasks_path(@project, task.id) > > I get the following URL: > > /projects/2/tasks.3 > > If I try this: > > link_to task.name, project_tasks_path(@project, @tasks) > > The error is even more cryptic. > > What I want is to have my /projects list all my projects. /projects/1 > list all the tasks for that project and link to each specific task. / > projects/1/tasks/2 will display all the notes attached to the tasks, > and link to each note. /projects/1/tasks/2/notes/3 will be a specific > note. > > Thanks. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.