我根据资源名称(帐户)有多个子域名,如
我想从地址栏中删除资源名称 school.mydomain.com/schools/sign_in到school.mydomain.com/sign_in 这是routes.rb文件
# school employee / teacher routes and resources
devise_for :employees, :skip => [:registrations], controllers: { sessions: 'employees/sessions', passwords: 'employees/passwords' }
devise_scope :employee do
get 'employees/edit' => 'employees/registrations#edit', :as => 'edit_employee_registration'
put 'employees' => 'employees/registrations#update', :as => 'employee_registration'
end
resources :employee
# school admin routes and resources
devise_for :schools, :skip => [:registrations], controllers: { sessions: 'schools/sessions', passwords: 'schools/passwords' }
devise_scope :school do
get 'schools/edit' => 'schools/registrations#edit', :as => 'edit_school_registration'
put 'schools' => 'schools/registrations#update', :as => 'school_registration'
end
resources :school
# student routes and resource
devise_for :students, :skip => [:registrations], controllers: { sessions: 'students/sessions', passwords: 'students/passwords' }
devise_scope :school_district do
get 'students/edit' => 'students/registrations#edit', :as => 'edit_student_registration'
put 'students' => 'students/registrations#update', :as => 'student_registration'
end
resources :student
您可以在Configuring routes Devise文档中阅读更多相关信息
我在我的项目routes.rb
file中测试了这个,通过改变devise_for
如下
Rails.application.routes.draw do
devise_for :users, path: ''
end
这是您在yourdomain/sign_in
上签名所需的输出
new_user_session GET /sign_in(.:format) devise/sessions#new
和我的rake routes
的输出
new_user_password GET /password/new(.:format) devise/passwords#new
edit_user_password GET /password/edit(.:format) devise/passwords#edit
user_password PATCH /password(.:format) devise/passwords#update
PUT /password(.:format) devise/passwords#update
POST /password(.:format) devise/passwords#create
cancel_user_registration GET /cancel(.:format) devise/registrations#cancel
new_user_registration GET /sign_up(.:format) devise/registrations#new
edit_user_registration GET /edit(.:format) devise/registrations#edit
user_registration PATCH / devise/registrations#update
PUT / devise/registrations#update
DELETE / devise/registrations#destroy
POST / devise/registrations#create
所以我引用
Configuring routes
Devise还附带默认路由。如果您需要自定义它们,您应该可以通过devise_for方法完成它。它接受以下几个选项:class_name,:path_prefix等,包括更改I18n的路径名的可能性:
devise_for :users, path: 'auth', path_names: { sign_in: 'login', sign_out: 'logout', password: 'secret', confirmation: 'verification', unlock: 'unblock', registration: 'register', sign_up: 'cmon_let_me_in' }
请务必查看devise_for文档以获取详细信息。
所以在devise_for
api docs你可以更好地理解如何使用path
和path_names
请确保不要在这些网址之间产生冲突