ruby-on-rails – 找不到id = sign_out的用户

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 找不到id = sign_out的用户前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
注销链接在我的rails应用程序中不起作用.

我检查了下面列出的routes.rb,我的application.html.erb看起来遵循正确的路径.

得到以下错误.

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'

我的routes.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似乎是从我能看到的正确路线.

任何帮助是极大的赞赏!

<% 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 %>

我的用户控制器以及我怀疑这是问题所在,但不确定错误是什么.

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正在寻找路由文件顶部的路由.您的注销网址与users /:id匹配,因此它尝试使用sign_out作为ID来呈现show动作.

更新:

实际上,你真的需要devise_scope块中的最后一行吗?

原文链接:https://www.f2er.com/ruby/270605.html

猜你在找的Ruby相关文章