[英]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.