Take the 2-minute tour ×  I'm working on a Rails 3 task demo
project in which each instance of Project has many tasks, and
instances of Task belong to one project. However, this latter
relationship is optional, although it's defined in the Task
model as belongs_to :project.  Essentially, I want to be able to
have routes like the following:    I'm not sure if this is
possible or even good practice. Really what's most important is
for me to be able to create project-less tasks from within the
general tasks#index action, and tasks belonging to a project
from within the project#show action via links to new actions.
I've read Rails Routing from the Outside In, but it didn't
really explain what I'm going for.  Any help would be greatly
appreciated.  share|improve this question add comment  2 Answers
up vote 3 down vote accepted  This is actually more common than
you think. Here is a solution:  class TasksController <
ApplicationController before_filter :get_project before_filter
:get_tasks     def get_project