我陷入Rails tutorial试图配置Rails路由。
这是我的routes.rb:
SampleApp::Application.routes.draw do
match '/', :to => 'static_pages#home', :via => :get
match '/help',:to => 'static_pages#help', :via => :get
match '/about', :to => 'static_pages#about', :via => :get
match '/contact', :to => 'static_pages#contact', :via => :get
当我尝试访问“localhost”时,我得到:
没有路由匹配[GET]“/ static_pages / help”尝试运行rake路由 有关可用路线的更多信息。
我也尝试过:
match '/', :to => 'static_pages#home'
match '/help',:to => 'static_pages#help'
match '/about', :to => 'static_pages#about'
match '/contact', :to => 'static_pages#contact'
但是这会产生同样的错误。它只在我使用时有效:
get 'static_pages/about'
如何让localhost工作?
答案 0 :(得分:0)
尝试将以下内容放在routes.rb
的末尾match ':action' => 'static#:action'
/help
的请求将呈现app/views/static/help.html.erb
。不要忘记创建static
控制器,即使它是空的。
答案 1 :(得分:0)
试试这个:
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'