I don’t know enough about your data to know if this is a tree structure (self-referential join) or a parent-child in terms of 'a project has a task associated"
Either way the concept is the same. It’s trivial if you use RESTful routing.
map.resources :projects do |p|
<%=link_to “Create new project”, new_project_task_url(@project) %>
@tasks = @project.tasks.find :all
@task = @project.tasks.build
@task = @project.tasks.build(params[:task])
flash[:notice] = “Task added successfully!”
@project = Project.find(params[:project_id]) # the url sends the project in as params[:project_id]
flash[:notice] = "Project not found"
The key is to make sure to pass the id of the project around in every URL you use and scope everything using the associations. Notice when I find tasks I do @project.tasks.find(:all) instead of Task.find(:all). This is a great way to ensure that I only get the things I need.
@task = @project.tasks.build is the same as @task = Task.new(:project_id => some_id).
If this is not clear enough, let me know how I can help.