【发布时间】:2016-07-21 20:52:58
【问题描述】:
这肯定有一个明显的答案,但我不知所措。
我有一个跟踪网站的 Rails 应用程序。无论出于何种原因, localhost:3000/sites 都会指向我的索引页面。但是, localhost:3000/sites/index 会导致我的显示页面。
这是为什么?
以下是路由文件:
Rails.application.routes.draw do
resources :sites
以下是站点控制器:
class SitesController < ApplicationController
def index
end
def show
end
end
在视图/站点中,有 index.html.erb 和 show.html.erb 文件。前者显示在 /sites,后者显示在 /sites/index(和 /sites/show 正如人们所期望的那样)。
感谢您的帮助!
更新:
当我 rake 路线时,我得到:
Prefix Verb URI Pattern Controller#Action
sites GET /sites(.:format) sites#index
POST /sites(.:format) sites#create
new_site GET /sites/new(.:format) sites#new
edit_site GET /sites/:id/edit(.:format) sites#edit
site GET /sites/:id(.:format) sites#show
PATCH /sites/:id(.:format) sites#update
PUT /sites/:id(.:format) sites#update
DELETE /sites/:id(.:format) sites#destroy
这些路由是人们所期望的,但我想我只是对站点/索引假定索引是一个 :id 并因此路由要显示的请求感到惊讶。
我想我以前从未明确遇到过这种行为。
【问题讨论】:
标签: ruby-on-rails