即使在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/
答案 0 :(得分:3)
root 'pages#home'
仅设置根路由。这将仅匹配localhost:3000/
而不匹配localhost:3000/pages
您想要添加类似
的内容 get 'pages', to: 'pages#home'
允许/pages
正常工作。
查看http://edgeguides.rubyonrails.org/routing.html以详细了解路由和routes.rb
文件。