Rails - Devise,如何禁用一些默认路由? [英] Rails - Devise, how can I disable some default routes?

查看:153
本文介绍了Rails - Devise,如何禁用一些默认路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想完全禁用路由/ users / sign_in获取和发布。

I want to completely disable the routes /users/sign_in for get and post.

我可以使用以下方式成功覆盖它们:

I was able to successfully override them using the following:

  devise_for :users do
      get "/admin" => "devise/sessions#new", :as => :new_user_session
      post "/admin" => "devise/sessions#create", :as => :user_session
  end

当我运行rake路线时,我看到以下内容:

And when I run rake routes I see the following:

    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访问登录/签到。但是我想完全删除最后两行,是可能吗?

I can access the sign in from /admin as well as from /users/sign_in. But I want to completely remove the last two rows, is it possible?

我尝试了一些不同的组合,从文档,似乎这样做,但它也覆盖了一些有用的,如密码/新密码/编辑路线。

I tried some different combinations from the documentation which seems to do it but it also overrides some useful ones, like the password/new and password/edit routes.

推荐答案

Katz的解决方案不再像Cirulli所说。

Katz's solution no longer works as noted by 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

这篇关于Rails - Devise,如何禁用一些默认路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆