开发者

Routing Error, Michael Hartl's Screencasts from railstutorial.org

I am following Michael Hartl's Screencasts from railstutorial.org. According to chapter 5, I changed 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

and _footer.html.erb to:

  • <%= link_to "About", about_path %>
  • <%= link_to "Contact", contact_path %>

and _header.html.erb to:

 <% 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>

I am new to Ruby on Rails. I am getting a Routing Error in the browser

No route matches "/pages/contact"

I am using ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux], rails 3.0.7 and 开发者_JAVA百科gem 1.6.2 Please help.


Your routes are set up a level. There is no route for /pages/contact, the correct route is "/contact" given your routes file.


For late comers, I just had this same issue. The code from the tutorial shouldn't have an end after those match statements. If you look at the last line of config/routes.rb, you'll see and end there. That's the only end you need.

Instead of:

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

It should be:

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜