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

后端 未结 7 1722
挽巷
挽巷 2021-01-06 04:10

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         


        
相关标签:
7条回答
  • 2021-01-06 04:17

    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

    0 讨论(0)
  • 2021-01-06 04:20

    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
    
    0 讨论(0)
  • 2021-01-06 04:21

    You could point to "/" or root_path in stead of '/static_pages/home'. No need to point two routes to the same place...

    0 讨论(0)
  • 2021-01-06 04:22

    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'

    0 讨论(0)
  • 2021-01-06 04:24

    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.

    0 讨论(0)
  • 2021-01-06 04:28

    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.

    0 讨论(0)
提交回复
热议问题