简体   繁体   English

Rails Devise,没有路由匹配'/users/sign_out' -> SignOut/Logout Routes 问题

[英]Rails Devise, No route matches '/users/sign_out' -> SignOut/Logout Routes problem

I have a app using devise to login/out, and view/create profiles.我有一个使用 devise 登录/退出和查看/创建配置文件的应用程序。 As of yet users may create and delete profiles although there is only supposed to be one profile per user.到目前为止,用户可以创建和删除配置文件,尽管每个用户应该只有一个配置文件。 I have set up my routes just about without problems until comes the SignOut/LogOut from the whole app.在整个应用程序出现注销/注销之前,我已经设置了我的路线几乎没有问题。 Ultimately the error log is all I can decipher, and seems that routes.rb needs some modification for this to work, but I am stumped.最终,我只能破译错误日志,而且似乎 routes.rb 需要进行一些修改才能使其正常工作,但我很困惑。 Here are the errors and routes.rb: /log/production.log:以下是错误和 routes.rb:/log/production.log:

Started DELETE "/users/sign_out" for 127.0.0.1 at 2020-01-26 01:56:53 -0500
ActionController::RoutingError (No route matches [DELETE] "/users/sign_out"):

routes.rb路由文件

Rails.application.routes.draw do
devise_for :users, :controllers => {:sessions => "users/sessions" }

resources :profiles, only: [:new, :create, :edit, :update, :destroy]

devise_scope :user do
authenticated :user do
root to: 'profiles#index', as: :authenticated_root
get '/profiles/new' => 'profiles#new'
match '/profiles' => 'profiles#create', via: [:get, :post]
get '/profiles/:id' => 'profiles#show'
get '/profiles/:id/edit' => 'profiles#edit'
match '/profiles/:id' => 'profiles#update', via: [:get, :post]
delete '/profiles' => 'profiles#destroy', via: [:get, :post]
end
unauthenticated :user do
root to: 'devise/sessions#new', as: :unauthenticated_root
match '/users/sign_in' => 'devise/sessions#create', via: [:get, :post]
delete '/users/sign_out' => 'devise/sessions#destroy'
end
end
end

I read that using resources :users may affect devise sessions controller, in that I would need a UsersController, however haven't included resources :users in my routes, and/or for a similar error.我读到使用资源 :users 可能会影响设计会话控制器,因为我需要一个 UsersController,但是我的路由中没有包含资源 :users 和/或类似的错误。

You placed the sign-out route in the unauthenticated block in your routes.rb您将退出路由放置在routes.rb unauthenticated routes.rb unauthenticated块中

unauthenticated :user do
  # ..
  delete '/users/sign_out' => 'devise/sessions#destroy'
end

What doesn't makes sense, only authenticated users can sign out.什么没有意义,只有经过身份验证的用户才能退出。 Just move that method into the authenticated :user block above:只需将该方法移动到上面经过authenticated :user块中即可:

authenticated :user do
  # ..
  delete '/users/sign_out' => 'devise/sessions#destroy'
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Rails 3.1中设计路线问题,没有路线匹配[GET]“ / users / sign_out” - Devise routes issue in Rails 3.1 with No route matches [GET] “/users/sign_out” Rails设计错误“没有路由匹配[GET]”/ users / sign_out“” - Rails Devise Error “No route matches [GET] ”/users/sign_out“” Rails 3 with Devise:没有路由匹配/ d / users / sign_out - Rails 3 with Devise: No route matches /d/users/sign_out Rails 3 Devise-获取“没有路线匹配” / users / sign_out“” - Rails 3 Devise - Getting “ No route matches ”/users/sign_out“ ” 设备-没有路线与[GET]“ / users / sign_out”匹配-Rails 4 - DEVISE - No route matches [GET] “/users/sign_out” - Rails 4 没有路线匹配“/users/sign_out” devise rails 3 - No route matches "/users/sign_out" devise rails 3 设计/Rails:没有路由匹配 [GET] “/users/sign_out” - Devise/Rails: No route matches [GET] “/users/sign_out” 无法使用Devise gem在Rails应用中注销,没有路线与/ users / sign_out匹配 - Unable to sign out in a Rails app, using Devise gem, no route matches /users/sign_out 设计没有路线匹配[GET]“/ users / sign_out” - devise No route matches [GET] “/users/sign_out” 设计路由错误:没有路由与[GET]“ / users / sign_out”匹配 - Devise routing error: No route matches [GET] “/users/sign_out”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM