在 devise_for 的路由中实现 : except
通过使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 devise_for 更改路径和名称默认网址
我建议将路径名保留为sign_in、sign_out 和sign_up,因为登录看起来像是乱码。
此外,从长远来看,有选择地编辑这些默认值可能只会使您的路线更加混乱。因此,除非有充分的理由覆盖默认值,否则您应该采用设备推荐的方式。
Use devise_for to change the path and names of the default urls
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.