Rails 3 + Devise - Как заставить работать вложенные ресурсы / маршруты? - PullRequest
1 голос
/ 01 апреля 2012

В моем файле rout.rb единственные записи, которые у меня есть:

devise_for :users, :path => "accounts"

resources :users do
  resource :profile
end

но когда я запускаю "rake route", я вижу, что для пользователя все еще есть сопоставленные ресурсы, например, new, create, edit, update и т. Д. ... это вызывает конфликт с некоторыми путями разработки, такими как new_user_registration_path

        new_user_session GET    /accounts/sign_in(.:format)            devise/sessions#new
            user_session POST   /accounts/sign_in(.:format)            devise/sessions#create
    destroy_user_session DELETE /accounts/sign_out(.:format)           devise/sessions#destroy
           user_password POST   /accounts/password(.:format)           devise/passwords#create
       new_user_password GET    /accounts/password/new(.:format)       devise/passwords#new
      edit_user_password GET    /accounts/password/edit(.:format)      devise/passwords#edit
                         PUT    /accounts/password(.:format)           devise/passwords#update
cancel_user_registration GET    /accounts/cancel(.:format)             devise/registrations#cancel
       user_registration POST   /accounts(.:format)                    devise/registrations#create
   new_user_registration GET    /accounts/sign_up(.:format)            devise/registrations#new
  edit_user_registration GET    /accounts/edit(.:format)               devise/registrations#edit
                         PUT    /accounts(.:format)                    devise/registrations#update
                         DELETE /accounts(.:format)                    devise/registrations#destroy
            user_profile POST   /users/:user_id/profile(.:format)      profiles#create
        new_user_profile GET    /users/:user_id/profile/new(.:format)  profiles#new
       edit_user_profile GET    /users/:user_id/profile/edit(.:format) profiles#edit
                         GET    /users/:user_id/profile(.:format)      profiles#show
                         PUT    /users/:user_id/profile(.:format)      profiles#update
                         DELETE /users/:user_id/profile(.:format)      profiles#destroy
                   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
                         PUT    /users/:id(.:format)                   users#update
                         DELETE /users/:id(.:format)                   users#destroy

Как мне избавиться от дополнительных пользовательских ресурсов, которые появляются в нижней части этого вывода?

Ответы [ 2 ]

0 голосов
/ 16 ноября 2013

Лучший способ сделать это - определить ваши Devise (не вложенные) маршруты, используя 'devise_for:', а затем в отдельном блоке выполнить

resources :users, :only => :none do
  resource :profile
end

Используя ': исключением =>:all 'останавливает любые не вложенные Users маршруты от определения и переопределения ваших маршрутов Devise, но все равно создает все ваши users/3/profile маршруты.Затем добавьте :path => "accounts" для замены users

, чтобы ваш код выглядел как

devise_for :users, :path => "accounts"

resources :users , :path => "accounts", :only => :none do
  resource :profile
end
0 голосов
/ 01 апреля 2012

Если вы хотите, скажем, индексировать и показать, попробуйте:

devise_for :users, :path => "accounts", :only => [:index, :show] do 
  resource :profile
end
...