找不到id = sign_out的用户 [英] Couldn't find User with id=sign_out

查看:167
本文介绍了找不到id = sign_out的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经检查了我的routes.rb,下面列出了我的application.html.erb看起来



获取以下错误。

  ActiveRecord :: RecordNotFound在UsersController#show 

找不到用户id = sign_out
Rails.root:/ Users / patrickwalsh / rails_projects / ytutorial

应用程序跟踪|框架跟踪|完整跟踪
app / controllers / users_controller.rb:4:在`show'
lib / disable_assets_logger.rb:11:在`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 / session#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'=> '用户#显示'
结束
资源:教程
资源:仅注释:[:show,:create,:update,,destroy]

resources:教程做
成员{post:vote}
end

如果Rails.env ==开发
匹配'errors / 404'=> 'errors#error_404'
match'errors / 500'=> 'error#error_500'
end

除非Rails.application.config.consider_all_requests_local
匹配'* not_found',到:'errors#error_404'
end

match'tagged'=> 'tutorials#tagged',:as => 'tagged'
end

和我的application.html似乎遵循正确的路由从我可以看到。



任何帮助是非常感谢!

 <%if current_user.present? %GT; 
< li><%= link_to注销,destroy_user_session_path,(:method =>delete)%>< / li>
<%else%>
< li><%= link_to登录,new_user_session_path%>< / li>
< li><%= link_to注册,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 / sign_out'=> 'devise / sessions#destroy'

在你的 devise_scope 。 Rails正在从路由文件顶部寻找路由。您的登出网址匹配 users /:id ,因此它试图以 sign_out 作为ID来呈现显示操作。



更新:



其实你真的需要你的 devise_scope中的最后一行块?


Sign-out link isn't working in my rails application.

I have checked my routes.rb which is listed below and my application.html.erb looks to follow the right path.

Getting the following error.

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'

My 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

and my application.html which seems to be following the right route from what I can see.

Any help is greatly appreciated!

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

解决方案

You need to move:

devise_for :users do get '/users/sign_out' => 'devise/sessions#destroy' 

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.

UPDATE:

Actually, do you really need the last line in your devise_scope block?

这篇关于找不到id = sign_out的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆