Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Viewing Todo Items: Part 1

Error: No route matches.... missing required keys: [:id]

Here is the error I'm receiving.

     No route matches {:action=>"show", :controller=>"reminder_detail", :med_reminder_id=>#<MedReminder id: 1, medication: "My Medication Name", created_at: "2014-11-25 05:57:58", updated_at: "2014-11-25 05:57:58">, :id=>nil, :format=>nil} missing required keys: [:id]

I can fix this error by changing the code from:

<%= link_to "Add Reminders", med_reminder_reminder_detail_path(med_reminder) %>
<%= link_to "Add Reminders", med_reminder_reminder_detail_path(med_reminder, :id) %>

However, this leads to a different error as it then routes to /med_reminders/3/reminder_detail/id - the 'id' being what breaks the link.

Any ideas?

3 Answers

Brandon Barrette
Brandon Barrette
20,485 Points

In your routes.rb file, what is the route that you are expecting here?

Here is how it is setup in my routes.rb - sorry for the slow response.

resources :med_reminders do
    resources :reminder_detail
end

It is a nested route so it looks like you need to pass in the :reminder_id resource as well to the path helper in the view.