在我的应用程序上使用 Devise 注销时出现问题

发布于 2024-11-18 20:41:30 字数 9458 浏览 3 评论 0原文

我正在更新我的应用程序,因此我使用 Devise gem 进行身份验证。一切似乎都运行良好,除了我似乎无法注销这一事实。

我收到错误:

Couldn't find User with ID=sign_out
Parameters:
{"id"=>"sign_out"}

我可以将错误追溯到用户控制器中的显示操作:

  def show
    @user = User.find(params[:id])
  end

问题是我不确定它为什么尝试为我的用户呈现显示操作。总的来说,我的页面具有以下格式:

<% if user_signed_in? %>
    <%= render 'shared/feed_home' %>
<% else %>
  <%= render 'shared/splash' %>
<% end %>

根据设计说明,我的注销路径如下所示:

<li><%= link_to "Sign out", destroy_user_session_path %></li>

如果用户未登录,它应该呈现基本上是静态 html 的启动页面。关于如何提供帮助有什么建议吗?即使你能让我在问题上处于正确的位置,我也会非常感激。

Here is my routes file:


  devise_for :users
  resources :users do
    member do
      get :following, :followers, :following_tags, :following_posts
    end
  end
  resources :posts 

  resources :votes
  resources :comments
  resources :tags
  resources :events

  #resources :posts,    :only => [:create, :destroy, :show]
  resources :relationships, :only => [:create, :destroy]

  root :to =>'pages#subscribed'


  match '/contact', :to => 'pages#contact'
  match '/about',   :to => 'pages#about'
  match '/live',   :to => "pages#home"
  match '/voted', :to => 'pages#highest_voted'
  match '/signup',  :to => 'users#new'

这是我的耙子路线:

        new_user_session GET    /users/sign_in(.:format)             {:action=>"new", :controller=>"devise/sessions"}
            user_session POST   /users/sign_in(.:format)             {:action=>"create", :controller=>"devise/sessions"}
    destroy_user_session DELETE /users/sign_out(.:format)            {:action=>"destroy", :controller=>"devise/sessions"}
           user_password POST   /users/password(.:format)            {:action=>"create", :controller=>"devise/passwords"}
       new_user_password GET    /users/password/new(.:format)        {:action=>"new", :controller=>"devise/passwords"}
      edit_user_password GET    /users/password/edit(.:format)       {:action=>"edit", :controller=>"devise/passwords"}
                         PUT    /users/password(.:format)            {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET    /users/cancel(.:format)              {:action=>"cancel", :controller=>"devise/registrations"}
       user_registration POST   /users(.:format)                     {:action=>"create", :controller=>"devise/registrations"}
   new_user_registration GET    /users/sign_up(.:format)             {:action=>"new", :controller=>"devise/registrations"}
  edit_user_registration GET    /users/edit(.:format)                {:action=>"edit", :controller=>"devise/registrations"}
                         PUT    /users(.:format)                     {:action=>"update", :controller=>"devise/registrations"}
                         DELETE /users(.:format)                     {:action=>"destroy", :controller=>"devise/registrations"}
          following_user GET    /users/:id/following(.:format)       {:action=>"following", :controller=>"users"}
          followers_user GET    /users/:id/followers(.:format)       {:action=>"followers", :controller=>"users"}
     following_tags_user GET    /users/:id/following_tags(.:format)  {:action=>"following_tags", :controller=>"users"}
    following_posts_user GET    /users/:id/following_posts(.:format) {:action=>"following_posts", :controller=>"users"}
                   users GET    /users(.:format)                     {:action=>"index", :controller=>"users"}
                         POST   /users(.:format)                     {:action=>"create", :controller=>"users"}
                new_user GET    /users/new(.:format)                 {:action=>"new", :controller=>"users"}
               edit_user GET    /users/:id/edit(.:format)            {:action=>"edit", :controller=>"users"}
                    user GET    /users/:id(.:format)                 {:action=>"show", :controller=>"users"}
                         PUT    /users/:id(.:format)                 {:action=>"update", :controller=>"users"}
                         DELETE /users/:id(.:format)                 {:action=>"destroy", :controller=>"users"}
                   posts GET    /posts(.:format)                     {:action=>"index", :controller=>"posts"}
                         POST   /posts(.:format)                     {:action=>"create", :controller=>"posts"}
                new_post GET    /posts/new(.:format)                 {:action=>"new", :controller=>"posts"}
               edit_post GET    /posts/:id/edit(.:format)            {:action=>"edit", :controller=>"posts"}
                    post GET    /posts/:id(.:format)                 {:action=>"show", :controller=>"posts"}
                         PUT    /posts/:id(.:format)                 {:action=>"update", :controller=>"posts"}
                         DELETE /posts/:id(.:format)                 {:action=>"destroy", :controller=>"posts"}
                   votes GET    /votes(.:format)                     {:action=>"index", :controller=>"votes"}
                         POST   /votes(.:format)                     {:action=>"create", :controller=>"votes"}
                new_vote GET    /votes/new(.:format)                 {:action=>"new", :controller=>"votes"}
               edit_vote GET    /votes/:id/edit(.:format)            {:action=>"edit", :controller=>"votes"}
                    vote GET    /votes/:id(.:format)                 {:action=>"show", :controller=>"votes"}
                         PUT    /votes/:id(.:format)                 {:action=>"update", :controller=>"votes"}
                         DELETE /votes/:id(.:format)                 {:action=>"destroy", :controller=>"votes"}
                comments GET    /comments(.:format)                  {:action=>"index", :controller=>"comments"}
                         POST   /comments(.:format)                  {:action=>"create", :controller=>"comments"}
             new_comment GET    /comments/new(.:format)              {:action=>"new", :controller=>"comments"}
            edit_comment GET    /comments/:id/edit(.:format)         {:action=>"edit", :controller=>"comments"}
                 comment GET    /comments/:id(.:format)              {:action=>"show", :controller=>"comments"}
                         PUT    /comments/:id(.:format)              {:action=>"update", :controller=>"comments"}
                         DELETE /comments/:id(.:format)              {:action=>"destroy", :controller=>"comments"}
                    tags GET    /tags(.:format)                      {:action=>"index", :controller=>"tags"}
                         POST   /tags(.:format)                      {:action=>"create", :controller=>"tags"}
                 new_tag GET    /tags/new(.:format)                  {:action=>"new", :controller=>"tags"}
                edit_tag GET    /tags/:id/edit(.:format)             {:action=>"edit", :controller=>"tags"}
                     tag GET    /tags/:id(.:format)                  {:action=>"show", :controller=>"tags"}
                         PUT    /tags/:id(.:format)                  {:action=>"update", :controller=>"tags"}
                         DELETE /tags/:id(.:format)                  {:action=>"destroy", :controller=>"tags"}
                  events GET    /events(.:format)                    {:action=>"index", :controller=>"events"}
                         POST   /events(.:format)                    {:action=>"create", :controller=>"events"}
               new_event GET    /events/new(.:format)                {:action=>"new", :controller=>"events"}
              edit_event GET    /events/:id/edit(.:format)           {:action=>"edit", :controller=>"events"}
                   event GET    /events/:id(.:format)                {:action=>"show", :controller=>"events"}
                         PUT    /events/:id(.:format)                {:action=>"update", :controller=>"events"}
                         DELETE /events/:id(.:format)                {:action=>"destroy", :controller=>"events"}
           relationships POST   /relationships(.:format)             {:action=>"create", :controller=>"relationships"}
            relationship DELETE /relationships/:id(.:format)         {:action=>"destroy", :controller=>"relationships"}
                    root        /(.:format)                          {:controller=>"pages", :action=>"subscribed"}
                 contact        /contact(.:format)                   {:controller=>"pages", :action=>"contact"}
                   about        /about(.:format)                     {:controller=>"pages", :action=>"about"}
                    live        /live(.:format)                      {:controller=>"pages", :action=>"home"}
                   voted        /voted(.:format)                     {:controller=>"pages", :action=>"highest_voted"}
                  signup        /signup(.:format)                    {:controller=>"users", :action=>"new"}

I am in the process updating my app so I use the Devise gem for authentication. Everything appears to be working great, except for the fact that I can't seem to sign out.

I get the error:

Couldn't find User with ID=sign_out
Parameters:
{"id"=>"sign_out"}

I can trace the error back to the show action in my users controller:

  def show
    @user = User.find(params[:id])
  end

The problem is that I am not sure why it is trying to render the show action for my user. Overall my page has this format:

<% if user_signed_in? %>
    <%= render 'shared/feed_home' %>
<% else %>
  <%= render 'shared/splash' %>
<% end %>

As per devise instructions, my sign-out path looks like this:

<li><%= link_to "Sign out", destroy_user_session_path %></li>

If a user is not signed in, it should render the splash page which is basically static html. Any suggestions on how to help? Even if you could just put me in the right ball park in terms of the problem that would be much appreciated.

Here is my routes file:


  devise_for :users
  resources :users do
    member do
      get :following, :followers, :following_tags, :following_posts
    end
  end
  resources :posts 

  resources :votes
  resources :comments
  resources :tags
  resources :events

  #resources :posts,    :only => [:create, :destroy, :show]
  resources :relationships, :only => [:create, :destroy]

  root :to =>'pages#subscribed'


  match '/contact', :to => 'pages#contact'
  match '/about',   :to => 'pages#about'
  match '/live',   :to => "pages#home"
  match '/voted', :to => 'pages#highest_voted'
  match '/signup',  :to => 'users#new'

Here is my rake routes:

        new_user_session GET    /users/sign_in(.:format)             {:action=>"new", :controller=>"devise/sessions"}
            user_session POST   /users/sign_in(.:format)             {:action=>"create", :controller=>"devise/sessions"}
    destroy_user_session DELETE /users/sign_out(.:format)            {:action=>"destroy", :controller=>"devise/sessions"}
           user_password POST   /users/password(.:format)            {:action=>"create", :controller=>"devise/passwords"}
       new_user_password GET    /users/password/new(.:format)        {:action=>"new", :controller=>"devise/passwords"}
      edit_user_password GET    /users/password/edit(.:format)       {:action=>"edit", :controller=>"devise/passwords"}
                         PUT    /users/password(.:format)            {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET    /users/cancel(.:format)              {:action=>"cancel", :controller=>"devise/registrations"}
       user_registration POST   /users(.:format)                     {:action=>"create", :controller=>"devise/registrations"}
   new_user_registration GET    /users/sign_up(.:format)             {:action=>"new", :controller=>"devise/registrations"}
  edit_user_registration GET    /users/edit(.:format)                {:action=>"edit", :controller=>"devise/registrations"}
                         PUT    /users(.:format)                     {:action=>"update", :controller=>"devise/registrations"}
                         DELETE /users(.:format)                     {:action=>"destroy", :controller=>"devise/registrations"}
          following_user GET    /users/:id/following(.:format)       {:action=>"following", :controller=>"users"}
          followers_user GET    /users/:id/followers(.:format)       {:action=>"followers", :controller=>"users"}
     following_tags_user GET    /users/:id/following_tags(.:format)  {:action=>"following_tags", :controller=>"users"}
    following_posts_user GET    /users/:id/following_posts(.:format) {:action=>"following_posts", :controller=>"users"}
                   users GET    /users(.:format)                     {:action=>"index", :controller=>"users"}
                         POST   /users(.:format)                     {:action=>"create", :controller=>"users"}
                new_user GET    /users/new(.:format)                 {:action=>"new", :controller=>"users"}
               edit_user GET    /users/:id/edit(.:format)            {:action=>"edit", :controller=>"users"}
                    user GET    /users/:id(.:format)                 {:action=>"show", :controller=>"users"}
                         PUT    /users/:id(.:format)                 {:action=>"update", :controller=>"users"}
                         DELETE /users/:id(.:format)                 {:action=>"destroy", :controller=>"users"}
                   posts GET    /posts(.:format)                     {:action=>"index", :controller=>"posts"}
                         POST   /posts(.:format)                     {:action=>"create", :controller=>"posts"}
                new_post GET    /posts/new(.:format)                 {:action=>"new", :controller=>"posts"}
               edit_post GET    /posts/:id/edit(.:format)            {:action=>"edit", :controller=>"posts"}
                    post GET    /posts/:id(.:format)                 {:action=>"show", :controller=>"posts"}
                         PUT    /posts/:id(.:format)                 {:action=>"update", :controller=>"posts"}
                         DELETE /posts/:id(.:format)                 {:action=>"destroy", :controller=>"posts"}
                   votes GET    /votes(.:format)                     {:action=>"index", :controller=>"votes"}
                         POST   /votes(.:format)                     {:action=>"create", :controller=>"votes"}
                new_vote GET    /votes/new(.:format)                 {:action=>"new", :controller=>"votes"}
               edit_vote GET    /votes/:id/edit(.:format)            {:action=>"edit", :controller=>"votes"}
                    vote GET    /votes/:id(.:format)                 {:action=>"show", :controller=>"votes"}
                         PUT    /votes/:id(.:format)                 {:action=>"update", :controller=>"votes"}
                         DELETE /votes/:id(.:format)                 {:action=>"destroy", :controller=>"votes"}
                comments GET    /comments(.:format)                  {:action=>"index", :controller=>"comments"}
                         POST   /comments(.:format)                  {:action=>"create", :controller=>"comments"}
             new_comment GET    /comments/new(.:format)              {:action=>"new", :controller=>"comments"}
            edit_comment GET    /comments/:id/edit(.:format)         {:action=>"edit", :controller=>"comments"}
                 comment GET    /comments/:id(.:format)              {:action=>"show", :controller=>"comments"}
                         PUT    /comments/:id(.:format)              {:action=>"update", :controller=>"comments"}
                         DELETE /comments/:id(.:format)              {:action=>"destroy", :controller=>"comments"}
                    tags GET    /tags(.:format)                      {:action=>"index", :controller=>"tags"}
                         POST   /tags(.:format)                      {:action=>"create", :controller=>"tags"}
                 new_tag GET    /tags/new(.:format)                  {:action=>"new", :controller=>"tags"}
                edit_tag GET    /tags/:id/edit(.:format)             {:action=>"edit", :controller=>"tags"}
                     tag GET    /tags/:id(.:format)                  {:action=>"show", :controller=>"tags"}
                         PUT    /tags/:id(.:format)                  {:action=>"update", :controller=>"tags"}
                         DELETE /tags/:id(.:format)                  {:action=>"destroy", :controller=>"tags"}
                  events GET    /events(.:format)                    {:action=>"index", :controller=>"events"}
                         POST   /events(.:format)                    {:action=>"create", :controller=>"events"}
               new_event GET    /events/new(.:format)                {:action=>"new", :controller=>"events"}
              edit_event GET    /events/:id/edit(.:format)           {:action=>"edit", :controller=>"events"}
                   event GET    /events/:id(.:format)                {:action=>"show", :controller=>"events"}
                         PUT    /events/:id(.:format)                {:action=>"update", :controller=>"events"}
                         DELETE /events/:id(.:format)                {:action=>"destroy", :controller=>"events"}
           relationships POST   /relationships(.:format)             {:action=>"create", :controller=>"relationships"}
            relationship DELETE /relationships/:id(.:format)         {:action=>"destroy", :controller=>"relationships"}
                    root        /(.:format)                          {:controller=>"pages", :action=>"subscribed"}
                 contact        /contact(.:format)                   {:controller=>"pages", :action=>"contact"}
                   about        /about(.:format)                     {:controller=>"pages", :action=>"about"}
                    live        /live(.:format)                      {:controller=>"pages", :action=>"home"}
                   voted        /voted(.:format)                     {:controller=>"pages", :action=>"highest_voted"}
                  signup        /signup(.:format)                    {:controller=>"users", :action=>"new"}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟花肆意 2024-11-25 20:41:30

实际上,忽略我之前的回答并尝试这个:

<li><%= link_to "Sign out", destroy_user_session_path, :method => :delete %></li>

Actually, ignore my previous answer and try this:

<li><%= link_to "Sign out", destroy_user_session_path, :method => :delete %></li>
美胚控场 2024-11-25 20:41:30

问题可能出在您的 routes.rb 文件中。您需要适当地路由user/signout,并且它需要位于用户的路由之上,因为路由是从上到下工作的。如果您发布路线文件,我可以提供更多帮助。

您的 devise_for :users 上方是否有 resources:users

我想你也可以尝试确定设计路线的范围:

    devise_scope :users do
      get "sign_out", :to => "devise/sessions#destroy"
    end

The problem might be in your routes.rb file. You need to route user/signout appropriately and it needs to be above the route for your users, because routes work from the top down. If you post your routes file, I can help more.

Do you maybe have a resources :users above your devise_for :users?

I guess you can also try scoping the devise routes:

    devise_scope :users do
      get "sign_out", :to => "devise/sessions#destroy"
    end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文