路由错误::没有路由匹配[GET]"/ static_pages/about"

Abh*_*nay 2 ruby-on-rails custom-routes railstutorial.org

我在阅读Michael Hartl的教程时遇到了这个错误.第5.3.2节(Rails路由).

我的routes.rb文件的内容是

SampleApp::Application.routes.draw do
   root  'static_pages#home'
  match '/help',    to: 'static_pages#help',    via: 'get'
  match '/about',   to: 'static_pages#about',   via: 'get'
  match '/contact', to: 'static_pages#contact', via: 'get'
end
Run Code Online (Sandbox Code Playgroud)

我在static_pages的rspec是成功的..我已经按照每条指令但在尝试访问任何页面时仍然遇到此错误

http://localhost:3000/static_pages/home
http://localhost:3000/static_pages/about
http://localhost:3000/static_pages/contact
Run Code Online (Sandbox Code Playgroud)

这是我在这些页面上遇到的错误

动作控制器:捕获异常

Routing Error
No route matches [GET] "/static_pages/about"

Rails.root: /home/abhinay/rails_projects/sample_app

Application Trace | Framework Trace | Full Trace
Routes

Routes match in priority from top to bottom



  Helper     HTTP Verb  Path             Controller#Action
    Path / Url          
    root_path     GET       /                    static_pages#home
    help_path     GET      /help(.:format)   static_pages#help
    about_path    GET      /about(.:format)  static_pages#about
    contact_path  GET      /contact(.:format)    static_pages#contact
Run Code Online (Sandbox Code Playgroud)

Raj*_*Das 6

看你没有任何路线 "/static_pages/about"

所以你得到了错误

 Routing Error
 No route matches [GET] "/static_pages/about"
Run Code Online (Sandbox Code Playgroud)

根据你的路线,关于页面/about应该是网址

 http://localhost:300/about   
 http://localhost:300/contact 
 http://localhost:300/help
Run Code Online (Sandbox Code Playgroud)

它将实际上调用您的static_pages控制器和about该控制器的操作

从你得到的铁路路线的url helper

大概有:

about_path或者about_url应该使用

联系方式

contact_path 要么 contact_url

求助

help_path 要么 help_url