1

我被困在试图配置 Rails 路线的Rails 教程中。

这是我的路线.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 工作?

4

2 回答 2

0

尝试将以下内容放在 routes.rb 的末尾

match ':action' => 'static#:action'

/help然后将呈现一个请求app/views/static/help.html.erb。不要忘记创建static控制器,即使它是空的。

于 2012-11-03T15:22:26.053 回答
0

试试这个:

match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
于 2012-11-03T15:42:33.597 回答