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 trialRafael Flores
Courses Plus Student 22,056 PointsChanges on the application.html.erb caused 22 failures when bin/rake
During the changes of the header I experience an error on the page shown here: NameError in TodoLists#index Showing /Users/rafaelflores/projects/odot/app/views/layouts/application.html.erb where line #12 raised:
undefined local variable or method `root_path' for #<#<Class:0x007fa2644c8b88>:0x007fa267688628> Extracted source (around line #12): 10 11 12 13 14 15
<div class="nav">
<h1><%= link_to "Odot", root_path %></h1>
<ul>
<li><%= link_to "Todo Lists", todo_lists_path %></li>
</ul>
Rails.root: /Users/rafaelflores/projects/odot
I also ran the bin rake test and it caused 22 errors I am stuck. Please help
4 Answers
Maciej Czuchnowski
36,441 PointsDo you have root defined in your config/routes.rb file?
Steve Hunter
57,712 PointsI have the same issue and I don't have much defined in my config.rb
file, and nor do the lessons require it. I shall Google how to add that but may well be back asking for help later!
Cheers,
Steve.
Steve Hunter
57,712 PointsOuch - no, I don't understand that at all, Maciej Czuchnowski
There's two links added to the application.html.erb
file, which look like:
<div class="nav">
<h1><%= link_to "ODOT", root_path %></h1>
<ul>
<li><%= link_to "Todo_lists", todo_lists_path %></li>
</ul>
<br class="clear" />
</div>
So, presumably we need to define two routes. Typing rake routes
gives me:
treehouse:~/projects/odot (master) $ rake routes
Prefix Verb URI Pattern Controller#Action
todo_list_todo_items GET /todo_lists/:todo_list_id/todo_items(.:format) todo_items#index
POST /todo_lists/:todo_list_id/todo_items(.:format) todo_items#create
new_todo_list_todo_item GET /todo_lists/:todo_list_id/todo_items/new(.:format) todo_items#new
edit_todo_list_todo_item GET /todo_lists/:todo_list_id/todo_items/:id/edit(.:format) todo_items#edit
todo_list_todo_item GET /todo_lists/:todo_list_id/todo_items/:id(.:format) todo_items#show
PATCH /todo_lists/:todo_list_id/todo_items/:id(.:format) todo_items#update
PUT /todo_lists/:todo_list_id/todo_items/:id(.:format) todo_items#update
DELETE /todo_lists/:todo_list_id/todo_items/:id(.:format) todo_items#destroy
todo_lists GET /todo_lists(.:format) todo_lists#index
POST /todo_lists(.:format) todo_lists#create
new_todo_list GET /todo_lists/new(.:format) todo_lists#new
edit_todo_list GET /todo_lists/:id/edit(.:format) todo_lists#edit
todo_list GET /todo_lists/:id(.:format) todo_lists#show
PATCH /todo_lists/:id(.:format) todo_lists#update
PUT /todo_lists/:id(.:format) todo_lists#update
DELETE /todo_lists/:id(.:format) todo_lists#destroy
GET /todo_lists(.:format) todo_lists#index
POST /todo_lists(.:format) todo_lists#create
GET /todo_lists/new(.:format) todo_lists#new
GET /todo_lists/:id/edit(.:format) todo_lists#edit
GET /todo_lists/:id(.:format) todo_lists#show
PATCH /todo_lists/:id(.:format) todo_lists#update
PUT /todo_lists/:id(.:format) todo_lists#update
So the todo_lists_path
might already exist. I can't see root, though.
Help would be appreciated!
Steve.
Steve Hunter
57,712 PointsI added:
root 'todo_lists#index'
In my routes.rb
file, like this:
Rails.application.routes.draw do
resources :todo_lists do
resources :todo_items
end
resources :todo_lists
root 'todo_lists#index'
And it all seems to work fine.
Steve.
Maciej Czuchnowski
36,441 PointsThat's exactly what I meant, sorry for my late reply. Happy to see that you figured it out on your own :).