I'm working on a basic Rails app. To get things going, I created two scaffolds.
- calendar
- content_items
I then created the proper associations.
app/models/calendar.rb
class Calendar < ActiveRecord::Base
has_many :content_items
end
app/models/content_item.rb
class ContentItem < ActiveRecord::Base
belongs_to :calendar
end
routes.rb
resources :calendars do
resources :content_items
end
However, now when I try to view the content_items of a specific calendar, I get the following error:
ActionController::UrlGenerationError - No route matches {:action=>"show", :calendar_id=>nil, :controller=>"content_items", :id=>"5"} missing required keys: [:calendar_id]
It says the error is coming from: views/content_items/index.html.erb
<td><%= link_to 'Show', calendar_content_item_path(content_item.calendar, content_item) %></td>
I've tried a few different routes, but they lead to different errors. Do I need to update the model and/or controllers since I created the nested routes?