我正在构建一个Rails网站,并设置设计路线。到目前为止,我没有遇到麻烦,一切正常。但是,由于网站在管理和访问者位置之间划分,我希望用户能够从看似/admin/users/1/edit
的路径编辑他的个人资料并从/user/sign_in
登录/注销,或者user/sign_out
(没有admin
前缀)。
到目前为止,我设法使用或不使用前缀,但不能同时使用两者。
以下是我的路线档案的相关部分:
devise_for :users, only: %w['session#new session#destroy']
get '/admin' => 'home#admin', as: :admin
authenticate :user do
scope '/admin' do
resource :basics
resources :portfolios
resources :articles
devise_for :users, excepted: %w['sessions#new session#destroy']
end
end
以下是rake routes
的结果:
new_user_session GET /admin/users/sign_in(.:format) devise/sessions#new
user_session POST /admin/users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /admin/users/sign_out(.:format) devise/sessions#destroy
new_user_password GET /admin/users/password/new(.:format) devise/passwords#new
edit_user_password GET /admin/users/password/edit(.:format) devise/passwords#edit
user_password PATCH /admin/users/password(.:format) devise/passwords#update
PUT /admin/users/password(.:format) devise/passwords#update
POST /admin/users/password(.:format) devise/passwords#create
cancel_user_registration GET /admin/users/cancel(.:format) devise/registrations#cancel
new_user_registration GET /admin/users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /admin/users/edit(.:format) devise/registrations#edit
user_registration PATCH /admin/users(.:format) devise/registrations#update
PUT /admin/users(.:format) devise/registrations#update
DELETE /admin/users(.:format) devise/registrations#destroy
POST /admin/users(.:format) devise/registrations#create
怎么做呢?
提前谢谢
答案 0 :(得分:2)
我认为这可能只是一个错字,但请尝试改变:
devise_for :users, excepted: %w['sessions#new session#destroy']
为:
devise_for :users, except: %w['sessions#new session#destroy']