Unknown error with route.rb
Hey I am new to Rails and I keep getting this error whenever I ever go to localhost: 3000 /
Routing error
No route match [GET] "/" Try running rake routes for more information on available routes.
This is what the routes.rb file looks like.
SampleApp::Application.routes.draw do
get "static_pages/about"
get "static_pages/contact"
get "static_pages/help"
get "static_pages/home"
end
and the folder with my views looks like this:
views/static_pages/about.html.erb views/static_pages/contact.html.erb views/static_pages/help.html.erb views/static_pages/home.html.erb
I ran the rake routes command and got this:
Davids-MacBook-Air:sample_app DavidStevenson$ rake routes
static_pages_home GET /static_pages/home(.:format) static_pages#home
static_pages_help GET /static_pages/help(.:format) static_pages#help
static_pages_about GET /static_pages/about(.:format) static_pages#about
static_pages_contact GET /static_pages/contact(.:format) static_pages#contact
Any ideas on what is going wrong?
+3
source to share
3 answers
You just forgot to define your root route. Place this at the end of your file routes
:
root to: 'static_pages#home'
You will now see the static_pages_home page when you visit localhost:3000/
.
Check out this guide for all route information.
EDIT
This is how your file looks like routes
:
SampleApp::Application.routes.draw do
get "static_pages/about"
get "static_pages/contact"
get "static_pages/help"
get "static_pages/home"
root to: 'static_pages#home'
end
+5
source to share