2011-07-06 6 views
15

인증을 위해 Devise gem을 사용하기 위해 앱을 업데이트하는 중입니다. 내가 로그 아웃 할 수 없다는 사실을 제외하면 모든 것이 잘 작동하는 것처럼 보입니다.문제 내 앱에서 Devise로 로그 아웃

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

문제는 그것을 시도하는 이유는 확실하지 않다이다 : 내 사용자 컨트롤러에서 show 액션에 다시 오류를 추적 할 수

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

:

나는 오류를 얻을 내 사용자를 위해 show 액션을 렌더링합니다. 전체 내 페이지 형식이 있습니다 유증의 지시 사항에 따라

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

을 내 로그 아웃 경로는 다음과 같습니다 : 사용자가 로그인되지

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

경우는 시작 페이지를 렌더링해야하는 기본적으로 정적 HTML입니다. 어떻게 도울 수있는 제안이 있습니까? 비록 당신이 바로 볼 파크에 저를 넣을 수있을지라도, 그 점에 관해서는 크게 감사 할 것입니다.

 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 이 링크는 [어 문제가 해결

난 당신이 또한 유증 경로를 범위 지정 시도 할 수 있습니다 추측 Devise에 대한] [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 메소드가 아니라 delete 메소드를 원합니다. 'destroy_user_session DELETE /users/sign_out(.:format) {: action => "destroy", : controller => "devise/sessions"} ' – DGM

2

문제는 당신 routes.rb 파일에있을 수 있습니다 :

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' 

여기 내 레이크 경로입니다. user/signout을 적절하게 라우트해야하며 라우트가 위에서 아래로 작동하기 때문에 사용자의 라우트보다 위에 있어야합니다. 라우트 파일을 게시하면 더 도움이 될 수 있습니다.

devise_for :users 위에 resources :users이 있습니까? 사실, 내 이전의 대답을 무시

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

Devise는 다음과 같이 가정합니다. 그 길은 자동으로 내가 생각 했니? 가장 최근에 편집 한 내용에 따라 세션을 종료하기위한 기본 작성 경로로 연결됩니다. – Spencer

+0

또한 경로 파일을 게시했습니다. – Spencer

+0

예, 제 업데이트를 참조하십시오. 어떤 이유로 레일스는'sign_out'이 사용자 리소스의 ID라고 생각합니다. '레이크 루트 '가주는 것은 무엇입니까? – Slick23