When I run server browser show me something like this:
Routing Error
No route matches [GET] \"/static_pages/home\"
Try running rake routes for more informa
step 5.3.3 Rails tutorial
You don't have to refresh your page
http://localhost:3000/static_pages/home
but only change the URL by
http://localhost:3000/
because you define 'static_pages/home' as root '/'.
For me it works
you should add :as keword to define XXX_path,such as root :to => 'static_pages#home'
match '/', to: 'static_pages#home', :as => :home
match '/help', to: 'static_pages#help', :as => :help
match '/about', to: 'static_pages#about', :as => :about
match '/contact', to: 'static_pages#contact', :as => :contact
You could point to "/"
or root_path
in stead of '/static_pages/home'
. No need to point two routes to the same place...
There is no route set for the url '/static_pages/home'
Although root points to static_pages controller with action home, it still responds to the path '/' and not '/static_pages/home'
If you add
match '/static_pages/home', :to =>'static_pages#home'
You will get the expected response for '/static_pages/home'
I just got the same error as szatan when I followed the Ruby on Rails tutorial.
The error is because, previously, we test URL was http://localhost:3000/static_pages/help
since the action is in static_pages. But, after changing routes.rb
from
get 'static_pages/help' to
match '/help', to: 'static_pages#help
The URL should changed to http://localhost:3000/help
since we tell Rails server to route the path /help
to static_pages#help
. We shouldn't expect the user to know the path /static_pages/help
.
Remember to remove the "public/index.html" file.
You can define all the routes properly, but if you leave this file, you won't be routing it properly.