Rails 设计,如何正确嵌套资源

Rails Devise, how to correctly nest resources

这是我的问题,我想正确嵌套我的设计路线:

user_je_session POST   /users/jes/:je_id/sign_in(.:format)

至:

user_je_session POST   /jes/:je_id/users/sign_in(.:format)

objective 是我的用户可以拥有多个帐户,具体取决于他们要访问的“je”。

这是我的实际路线:

root to: 'pages#home'
devise_for :admins, controllers: { sessions: 'admin/sessions', registrations: 'admin/registrations' }

resources :jes, param: :nom do
  devise_for :users, controllers: { sessions: 'users/sessions', registrations: 'users/registrations' }
end

感谢您的帮助

我觉得 devise_scope 更容易使用。您可以根据需要自定义设计路线。像这样的东西可能有用:

devise_for :admins, controllers: {
  sessions: 'admin/sessions',
  registrations: 'admin/registrations'
}
as :admin do
  # Please change to: value to your actual controller or action
  post '/jes/:je_id/users/sign_in', to: 'admin/sessions#create' 
end

请在文档页面上阅读更多内容。

https://github.com/heartcombo/devise/wiki/How-To:-Change-the-default-sign_in-and-sign_out-routes