在 devise_for 的路由中实现 : except

发布于 2024-12-25 06:55:46 字数 2394 浏览 0 评论 0原文

通过使用 user_auth 的 devise,它设置了一些默认路由(例如 /user/edit 和 /user/sign_in)。在routes.rb中我有

devise_scope :user do
  get 'signin' => 'devise/sessions#new'
  etc.
end

问题是/signin和/user/sign_in都可以链接到登录页面。我想知道如何使 /user/sign_in 链接处于非活动状态,这意味着导航到该页面时会出现 404 错误。

我的耙子路线是:

    new_user_session GET    /users/sign_in(.:format)            {:action=>"new", :controller=>"devise/sessions"}
        user_session POST   /users/sign_in(.:format)            {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session DELETE /users/sign_out(.:format)           {:action=>"destroy", :controller=>"devise/sessions"}
       user_password POST   /users/password(.:format)           {:action=>"create", :controller=>"devise/passwords"}
   new_user_password GET    /users/password/new(.:format)       {:action=>"new", :controller=>"devise/passwords"}
  edit_user_password GET    /users/password/edit(.:format)      {:action=>"edit", :controller=>"devise/passwords"}
                     PUT    /users/password(.:format)           {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET    /users/cancel(.:format)             {:action=>"cancel", :controller=>"registrations"}
   user_registration POST   /users(.:format)                    {:action=>"create", :controller=>"registrations"}
new_user_registration GET    /users/sign_up(.:format)            {:action=>"new", :controller=>"registrations"}
edit_user_registration GET    /users/edit(.:format)               {:action=>"edit", :controller=>"registrations"}
                     PUT    /users(.:format)                    {:action=>"update", :controller=>"registrations"}
                     DELETE /users(.:format)                    {:action=>"destroy", :controller=>"registrations"}
              signin GET    /signin(.:format)                   {:action=>"new", :controller=>"devise/sessions"}
             signout GET    /signout(.:format)                  {:action=>"destroy", :controller=>"devise/sessions"}
              signup GET    /signup(.:format)                   {:action=>"new", :controller=>"devise/registrations"}
             command GET    /command(.:format)                  {:action=>"edit", :controller=>"devise/registrations"}

By using devise for user_auth it sets up some default routes (e.g. /user/edit and /user/sign_in). In routes.rb I have

devise_scope :user do
  get 'signin' => 'devise/sessions#new'
  etc.
end

The problem is that both /signin and /user/sign_in work to link to the sign in page. I want to so how make the /user/sign_in link inactive meaning it gives a 404 error when navigating to that page.

My rake routes is:

    new_user_session GET    /users/sign_in(.:format)            {:action=>"new", :controller=>"devise/sessions"}
        user_session POST   /users/sign_in(.:format)            {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session DELETE /users/sign_out(.:format)           {:action=>"destroy", :controller=>"devise/sessions"}
       user_password POST   /users/password(.:format)           {:action=>"create", :controller=>"devise/passwords"}
   new_user_password GET    /users/password/new(.:format)       {:action=>"new", :controller=>"devise/passwords"}
  edit_user_password GET    /users/password/edit(.:format)      {:action=>"edit", :controller=>"devise/passwords"}
                     PUT    /users/password(.:format)           {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET    /users/cancel(.:format)             {:action=>"cancel", :controller=>"registrations"}
   user_registration POST   /users(.:format)                    {:action=>"create", :controller=>"registrations"}
new_user_registration GET    /users/sign_up(.:format)            {:action=>"new", :controller=>"registrations"}
edit_user_registration GET    /users/edit(.:format)               {:action=>"edit", :controller=>"registrations"}
                     PUT    /users(.:format)                    {:action=>"update", :controller=>"registrations"}
                     DELETE /users(.:format)                    {:action=>"destroy", :controller=>"registrations"}
              signin GET    /signin(.:format)                   {:action=>"new", :controller=>"devise/sessions"}
             signout GET    /signout(.:format)                  {:action=>"destroy", :controller=>"devise/sessions"}
              signup GET    /signup(.:format)                   {:action=>"new", :controller=>"devise/registrations"}
             command GET    /command(.:format)                  {:action=>"edit", :controller=>"devise/registrations"}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请叫√我孤独 2025-01-01 06:55:46

使用 devise_for 更改路径和名称默认网址

devise_for :users, :path => '', :path_names => { :sign_in => 'signin', :sign_out => 'signout', :sign_up => 'signup' }

我建议将路径名保留为sign_in、sign_out 和sign_up,因为登录看起来像是乱码。

此外,从长远来看,有选择地编辑这些默认值可能只会使您的路线更加混乱。因此,除非有充分的理由覆盖默认值,否则您应该采用设备推荐的方式。

Use devise_for to change the path and names of the default urls

devise_for :users, :path => '', :path_names => { :sign_in => 'signin', :sign_out => 'signout', :sign_up => 'signup' }

I would recommend leaving the path names as sign_in, sign_out, and sign_up since signin looks like gibberish.

Also, selectively editing these defaults will probably just make your routes more confusing in the long run. So, unless there is a great reason to overwrite the defaults, you should go with what devise recommends.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文