0

私はこれを持っています

devise_for :users
 resources :sites do
  resources :users
  get 'companies/search'
 end
 root :to => "welcome#index"
end

ルートは次のようになります

       site_users GET    /sites/:site_id/users(.:format)            users#index
                  POST   /sites/:site_id/users(.:format)            users#create
    new_site_user GET    /sites/:site_id/users/new(.:format)        users#new
   edit_site_user GET    /sites/:site_id/users/:id/edit(.:format)   users#edit
        site_user GET    /sites/:site_id/users/:id(.:format)        users#show
                  PUT    /sites/:site_id/users/:id(.:format)        users#update
                  DELETE /sites/:site_id/users/:id(.:format)        users#destroy
 site_companies_search GET /sites/:site_id/companies/search(.:format)  sites/:site_id/companies#search
            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
                  PUT    /sites/:id(.:format)                       sites#update
                  DELETE /sites/:id(.:format)                       sites#destroy
             root        /                                          welcome#index

しかし、このようなルートを持つ方法があるかどうか知りたい

       site_users GET    /:site_id/users(.:format)            users#index
                  POST   /:site_id/users(.:format)            users#create
    new_site_user GET    /:site_id/users/new(.:format)        users#new
   edit_site_user GET    /:site_id/users/:id/edit(.:format)   users#edit
        site_user GET    /:site_id/users/:id(.:format)        users#show
                  PUT    /:site_id/users/:id(.:format)        users#update
                  DELETE /:site_id/users/:id(.:format)        users#destroy

URL に /sites がないため、URL は

/sites/some_name/users 
/sites/some_name/users/new

/some_name/users 
/some_name/users/new

可能であればURLをクリーンアップします

4

2 に答える 2

2
resources :sites do
  get 'companies/search'
end
scope ':site_id' do
  resources :users
end
root :to => "welcome#index"
于 2012-05-22T20:34:54.200 に答える
1

inherited_resources などのリソース読み込みメカニズムに加えてこれを使用し、siteCRUD アクションを/に設定したい場合は、次のようにルートを描画できます。

resources :sites, :path => "" do
  get 'companies/search'

  resources :users
end

root :to => "welcome#index"
于 2012-05-22T21:00:29.337 に答える