导轨 4 路由 没有匹配的路由 [GET] "/help"



我不知道我犯了什么错误,这是如此基本的:

本地主机:3000

作为我的根,但如果我输入 localhost:3000/help,我会收到以下错误:

   Started GET "/help" for 127.0.0.1 at 2016-02-09 17:11:37 -0500
ActionController::RoutingError (No route matches [GET] "/help"):
  web-console (2.0.0.beta3) lib/action_dispatch/debug_exceptions.rb:22:in `middleware_call'
  web-console (2.0.0.beta3) lib/action_dispatch/debug_exceptions.rb:13:in `call'
  actionpack (4.2.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.2.2) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.2) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.2) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.2) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.2) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.2) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.2.2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
  rack (1.6.4) lib/rack/runtime.rb:18:in `call'
  activesupport (4.2.2) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  actionpack (4.2.2) lib/action_dispatch/middleware/static.rb:113:in `call'
  rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
  railties (4.2.2) lib/rails/engine.rb:518:in `call'
  railties (4.2.2) lib/rails/application.rb:164:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  rack (1.6.4) lib/rack/content_length.rb:15:in `call'
  rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
  /home/reed/.rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
  /home/reed/.rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
  /home/reed/.rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'

这是我的routes.rb:

Rails.application.routes.draw do
root 'static_pages#home'
get  'static_pages/help'
get  'static_pages/about'

结束

我在视图/static_pages下有文件帮助.html.erb,以下是文件内容:

    <% provide(:title, "Help") %>
<h1>StaticPages#help</h1>
<p>Find me in app/views/static_pages/help.html.erb</p

这是我的控制器:

class StaticPagesController < ApplicationController
    def home
    end
    def help
    end
end

这和 rails 应用程序一样基本。我不知道我做了什么,但如果你能看到错别字或我犯了错误,请告诉我。谢谢

你的语法有点不对劲。

你有:

Rails.application.routes.draw do
    root 'static_pages#home'
    get  'static_pages/help'
    get  'static_pages/about'
end

它应该是:

Rails.application.routes.draw do
    root 'static_pages#home'
    get  'help' => 'static_pages#help'
    get  'about' => 'static_pages#about'
end

您可以在此链接中查看相关的 rails 文档

最新更新