找不到 id=sign_out 的用户 [英] Couldn't find User with id=sign_out
问题描述
注销链接在我的 rails 应用程序中不起作用.
Sign-out link isn't working in my rails application.
我已经检查了下面列出的 routes.rb 并且我的 application.html.erb 看起来遵循正确的路径.
I have checked my routes.rb which is listed below and my application.html.erb looks to follow the right path.
出现以下错误.
ActiveRecord::RecordNotFound in UsersController#show
Couldn't find User with id=sign_out
Rails.root: /Users/patrickwalsh/rails_projects/ytutorial
Application Trace | Framework Trace | Full Trace
app/controllers/users_controller.rb:4:in `show'
lib/disable_assets_logger.rb:11:in `call'
我的路线.rb
Refectory::Application.routes.draw do
devise_for :users, :controllers => { :registrations => "users" }
devise_scope :user do
get 'login', to: "devise/sessions#new", as: "login"
get 'logout', to: "devise/sessions#destroy", as: "logout"
get 'logout', to: "users/sessions#destroy", as: "logout"
get 'signup', to: "users#new", as: "signup"
match '/users/:id', :to => 'users#show', :as => :user
end
root :to => 'tutorials#index'
devise_for :users do get '/users/sign_out' => 'devise/sessions#destroy'
get 'users/:id' => 'users#show'
end
resources :tutorials
resources :comments, only: [:show, :create, :update, :destroy]
resources :tutorials do
member { post :vote }
end
if Rails.env == "development"
match 'errors/404' => 'errors#error_404'
match 'errors/500' => 'errors#error_500'
end
unless Rails.application.config.consider_all_requests_local
match '*not_found', to: 'errors#error_404'
end
match 'tagged' => 'tutorials#tagged', :as => 'tagged'
end
和我的 application.html 从我所见,它似乎遵循了正确的路线.
and my application.html which seems to be following the right route from what I can see.
非常感谢任何帮助!
<% if current_user.present? %>
<li><%= link_to "Log out", destroy_user_session_path, (:method => "delete") %></li>
<% else %>
<li><%= link_to "Log in", new_user_session_path %></li>
<li><%= link_to "Sign up", new_user_registration_path %></li>
<% end %>
我的用户控制器以及我怀疑这就是问题所在,但不确定错误是什么.
My users controller as well as I have a suspicion this is where the problem lies but not sure what the error is.
class UsersController < Devise::RegistrationsController
def show
@user = User.find(params[:id])
@tutorials = @user.tutorials
end
end
推荐答案
你需要搬家:
devise_for :users do get '/users/sign_out' => 'devise/sessions#destroy'
超过你的devise_scope
.Rails 正在从 Routes 文件的顶部寻找路由.您的登出 url 与 users/:id
匹配,因此它试图以 sign_out
作为 ID 呈现显示操作.
over your devise_scope
. Rails is looking for routes from top of Routes file. Your sign out url matches users/:id
, hence it is trying to render show action with sign_out
being an id.
更新:
实际上,您真的需要 devise_scope
块中的最后一行吗?
Actually, do you really need the last line in your devise_scope
block?
这篇关于找不到 id=sign_out 的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!