我想完全禁用路由/ users / sign_in以获取和发布。
我能够使用以下方法成功覆盖它们:
devise_for :users do
get "/admin" => "devise/sessions#new", :as => :new_user_session
post "/admin" => "devise/sessions#create", :as => :user_session
end
当我运行rake路线时,我看到以下内容:
new_user_session GET /admin(.:format) {:controller=>"devise/sessions", :action=>"new"}
user_session POST /admin(.:format) {:controller=>"devise/sessions", :action=>"create"}
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
我可以从/ admin以及/ users / sign_in访问登录。但我想完全删除最后两行,是否可能?
我尝试了documentation的一些不同组合,它似乎也做了,但它也覆盖了一些有用的组合,比如密码/新密码/编辑路由。
答案 0 :(得分:23)
Katz的解决方案不再像Cirulli所说的那样有效。
请尝试以下操作。
devise_for :users, :skip => [:sessions]
as :user do
get "/admin" => "devise/sessions#new", :as => :new_user_session
post "/admin" => "devise/sessions#create", :as => :user_session
end
答案 1 :(得分:21)
您可以使用:skip选项来设计devise_for:
devise_for :users, :skip => [:sessions] do
get "/admin" => "devise/sessions#new", :as => :new_user_session
post "/admin" => "devise/sessions#create", :as => :user_session
end
当我在那之后运行rake路线时,我得到:
new_user_session GET /admin(.:format) {:controller=>"devise/sessions", :action=>"new"}
user_session POST /admin(.:format) {:controller=>"devise/sessions", :action=>"create"}
答案 2 :(得分:5)
这是
devise_for :users, skip: [:sessions,:registrations], controllers: {
omniauth_callbacks: "users/omniauth_callbacks"
}
答案 3 :(得分:1)
当您跳过sessions
控制器时,您最常将destroy
操作添加到自定义路由中:
as :user do
get "/admin" => "devise/sessions#new", :as => :new_user_session
post "/admin" => "devise/sessions#create", :as => :user_session
delete "/logout" => "devise/sessions#destroy", :as => :destroy_user_session
end