I have a model called Schedule that belongs_to a project. A project has_one schedule. I am trying to follow CRUD conventions but having some difficult. I have a page that lists all the projects and has a link next to each project to create a schedule. I started out with the following in my route file:
resources :schedules
Here's the problem. In the url of the 'new schedule' page there needs to be an :id that refers to the project that the schedule belongs to, that way when the schedule is created it will belong to the proper project. I don't know of a way to do that with resources, so I changed my routes code to:
match 'schedules/new/:id', to: 'schedules#new', as: :new_schedule, via: [:get, :post]
resources :schedules, except: [:new, :create]
For some reason, this page is blank. It's just white. How do I fix my routes? Thanks.
UPDATE:
I also tried changing my routes to the following:
resources :projects do
resources :schedules
end
This makes the url for a new schedule in the form of:
/projects/:project_id/schedules/new(.:format)
I think this is how it should be done, however, the form for new schedules is written as
form_for @schedule
and that produces the following error:
undefined method `schedules_path'
Any ideas?