ruby中路由的一个非常基本的问题

Har*_*ris 0 routes ruby-on-rails ruby-on-rails-3

我是ruby的新手,在创建示例应用程序时发现了一个问题,每当我默认执行http://127.0.0.1:3000/people/index时,会执行show action并将index作为参数.这是服务器日志:

 Started GET "/people/index" for
 127.0.0.1 at 2010-12-23 18:43:01 +0500 Processing by PeopleController#show as
 HTML Parameters: {"id"=>"index"}
Run Code Online (Sandbox Code Playgroud)

我在路径文件中有这个:

root :to => "people#index"   
resources :people
match ':controller(/:action(/:id(.:format)))'
Run Code Online (Sandbox Code Playgroud)

这里发生了什么,我该如何解决这个问题?

yfe*_*lum 5

路线

resources :people
Run Code Online (Sandbox Code Playgroud)

创建"子" - 路由

get    '/people'          => 'people#index'
get    '/people/new'      => 'people#new'
post   '/people'          => 'people#create'
get    '/people/:id'      => 'people#show'
get    '/people/:id/edit' => 'people#edit'
put    '/people/:id'      => 'people#update'
delete '/people/:id'      => 'people#destroy'
Run Code Online (Sandbox Code Playgroud)

实际上,所有这些子路线都包含(.:format)在公认路径的末尾.

路径/people/index将识别路径/people/:id,映射到操作#show.

路径/people将识别路径/people,映射到操作#index.

使用URL佣工people_path,并people_url/people路线.

为了让Rails在它支持REST并理解之前及时向后移动/people/index,请执行以下操作:

resources :people do
  get :index => 'people#index'
end
Run Code Online (Sandbox Code Playgroud)