路由错误,来自railstutorial.org的Michael Hartl的Screencast

时间:2011-05-07 19:27:35

标签: ruby-on-rails-3 routes rails-routing railstutorial.org

我正在关注来自railstutorial.org的Michael Hartl的截屏视频。根据第5章,我改变了 config / routes.rb to:

SampleApp::Application.routes.draw do
  match '/contact', :to => 'pages#contact'
  match '/about',   :to => 'pages#about'
  match '/help',    :to => 'pages#help'
  root :to => 'pages#home'
end

和_footer.html.erb:               

          
  • <%= link_to“关于”,about_path%>
  •       
  • <%= link_to“联系人”,contact_path%>
  •     
    
     和_header.html.erb到:

 <% logo = image_tag("logo.png", :alt => "Sample App", :class => "round") %>
 <%= link_to logo, root_path %>
 <nav class="round">
    <ul>
      <li><%= link_to "Home", root_path %></li>
      <li><%= link_to "Help", help_path %></li>

我是Ruby on Rails的新手。我在浏览器中收到路由错误

没有路线匹配“/ pages / contact”

我正在使用ruby 1.9.2p180(2011-02-18修订版30909)[x86_64-linux], rails 3.0.7和gem 1.6.2 请帮忙。

2 个答案:

答案 0 :(得分:1)

您的路线设置了一个级别。 / pages / contact没有路由,正确的路由是“/ contact”给出你的路由文件。

答案 1 :(得分:0)

对于后来者,我只是遇到了同样的问题。在这些end语句之后,教程中的代码不应该有match。如果你看一下config / routes.rb的最后一行,你会看到end。这是你需要的唯一目标。

而不是:

SampleApp::Application.routes.draw do
  match '/contact', :to => 'pages#contact'
  match '/about',   :to => 'pages#about'
  match '/help',    :to => 'pages#help'
  root :to => 'pages#home'
end

应该是:

SampleApp::Application.routes.draw do
  match '/contact', :to => 'pages#contact'
  match '/about',   :to => 'pages#about'
  match '/help',    :to => 'pages#help'
  root :to => 'pages#home'

 # All those commented out rules
 # All those commented out rules
 # All those commented out rules
end