Rails应用程序无法检测路由

时间:2017-03-22 17:15:24

标签: ruby-on-rails ruby

即使在routes.rb Rails中指定路线后,当我在浏览器中点击http://localhost:3000/pages时,我的No route matches [GET] "/pages" 应用程序也会出现以下错误。

Ruby版本: 2.2

Rails版本: 5.0

错误:

Rails.application.routes.draw do
  root 'pages#home'
end

的routes.rb

class PagesController < ApplicationController
  def home
  end
end

pages_controller.rb

<h2>Welcome Home</h2>
<p>After your long journey through rocky mountains and dry dust bowls you have finally neared the end.</p>

home.html.erb

upload/

1 个答案:

答案 0 :(得分:3)

root 'pages#home'仅设置根路由。这将仅匹配localhost:3000/而不匹配localhost:3000/pages

您想要添加类似

的内容

get 'pages', to: 'pages#home'允许/pages正常工作。

查看http://edgeguides.rubyonrails.org/routing.html以详细了解路由和routes.rb文件。