Since you have a nested resource/route, you need to pass an array containing both the @schedule
instance variable (holding the new Schedule
object) along with the @project instance variable (holding the parent Project
object) to your form_for
:
form_for [@project, @schedule]
EXPLANATION:
Your named match route (i.e., match 'schedules/new/:id'
) fails to route because the schedules#new
controller action is RESTful and thus does not accept an id
parameter. However, you correctly amended your route in your update – the parent-child association between projects/schedules should indeed be represented in your routes by nesting your resources.
The resulting path – /projects/:project_id/schedules/new
– requires that an array of objects be passed to your form_for
helper. The first must be an existing Project
object (thus satisfying the :project_id
parameter) and the second must be a new Schedule
object (which, by definition, will not yet have an id
attribute assigned).