Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Routing Error No route matches [GET] "/static_pages/home", tutorial

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 information on available routes. 

Rake routes shows me this:

root  /                  static_pages#home
help  /help(.:format)    static_pages#help
about  /about(.:format)   static_pages#about
contact  /contact(.:format) static_pages#contact

My routes.rb file:

MyApp::Application.routes.draw do
root :to => 'static_pages#home'

match '/help',    :to => 'static_pages#help'
match '/about',   :to => 'static_pages#about'
match '/contact', :to =>'static_pages#contact'


end

Anyone got an idea?

like image 375
szatan Avatar asked Dec 04 '22 02:12

szatan


2 Answers

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'

like image 113
Erez Rabih Avatar answered Dec 30 '22 04:12

Erez Rabih


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

like image 33
user3046555 Avatar answered Dec 30 '22 02:12

user3046555