0

Railsのroutes.rbには次のものがあります。

  resource :sign_up, only: [:new, :create]
  resources :users
  get 'users/activate/:token' => 'users#activate', as: 'activate_user'

これにより、次のルートが得られます。

       Prefix Verb   URI Pattern                      Controller#Action
      sign_up POST   /sign_up(.:format)               sign_ups#create
  new_sign_up GET    /sign_up/new(.:format)           sign_ups#new
        users GET    /users(.:format)                 users#index
              POST   /users(.:format)                 users#create
     new_user GET    /users/new(.:format)             users#new
    edit_user GET    /users/:id/edit(.:format)        users#edit
         user GET    /users/:id(.:format)             users#show
              PATCH  /users/:id(.:format)             users#update
              PUT    /users/:id(.:format)             users#update
              DELETE /users/:id(.:format)             users#destroy
activate_user GET    /users/activate/:token(.:format) users#activate

get 'users/activate/:token' ...私はそれを理解することはできませんが、ルートを取り除き、代わりにネストまたはスコーピングを使用したいと考えています。これを達成する方法はありますか?

ありがとう!

4

1 に答える 1

2

ユーザーの収集ルートを設定できます。

resources :users do
  collection do
    get 'activate/:token', :action => :activate, :as => :activate
  end
end

そして、次のようなルートが提供されます。

        Prefix Verb   URI Pattern                      Controller#Action
activate_users GET    /users/activate/:token(.:format) users#activate
         users GET    /users(.:format)                 users#index
               POST   /users(.:format)                 users#create
      new_user GET    /users/new(.:format)             users#new
     edit_user GET    /users/:id/edit(.:format)        users#edit
          user GET    /users/:id(.:format)             users#show
               PATCH  /users/:id(.:format)             users#update
               PUT    /users/:id(.:format)             users#update
               DELETE /users/:id(.:format)             users#destroy
于 2013-06-25T05:59:33.103 に答える