2011-07-06 71 views
15

我正在更新我的應用程序,因此我使用Devise gem進行身份驗證。除了我似乎無法退出這一事實之外,一切似乎都工作得很好。問題在我的應用程序中籤出設計

我得到的錯誤:

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

我可以跟蹤誤差回show動作在我的用戶控制:

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"} 
+0

使用此鏈接signout [退出問題解決了爲設計] [1]:http://stackoverflow.com/questions/6557311/no-route-matches-users-sign-out-devise-rails-3 –

回答

27

其實,忽略我以前的答案,試試這個:

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

我目前遠離我的電腦,無法測試這個。不過,我一回家就會測試它。再次感謝:) – Spencer

+0

沒問題。它看起來像Devise沒有生成註銷get方法,只是刪除。文件說,它應該,所以不知道爲什麼沒有。但它*應該*工作:-) – Slick23

+1

這完全是它 - 路線想要刪除方法,而不是get方法。 'destroy_user_session DELETE /users/sign_out(.:format){:action =>「destroy」,:controller =>「devise/sessions」} ' – DGM

2

問題可能是在你的routes.rb文件。您需要適當地路由user/signout,並且它需要位於用戶的路由之上,因爲路由是自上而下的。如果你張貼你的路線文件,我可以幫助更多。

您是否在devise_for :users之上有resources :users

我想你也可以嘗試將範圍的色器件路線:

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

設計應該provi我認爲自動路線?根據我最近的編輯,我只是​​鏈接到結束會話的默認設計路線。 – Spencer

+0

我也發佈了我的路線文件。 – Spencer

+0

是的,看我的更新。出於某些原因,rails認爲'sign_out'是用戶資源的ID。什麼'耙路線'給你? – Slick23