2012-02-12 1 views
2

2.2에서 3.2까지 시작하여 수년 동안 마이 그 레이션 된 레일 앱이 있습니다. Devise와 Omniauth를 사용하여 로그인 작업을하고 있습니다. 불행히도 마이그레이션 중에 나는 뭔가를 엉망으로 생각합니다.레일즈 앱이 자바 스크립트에서 'destroy_user_session_path'를 찾을 수 없습니다.

내가 설정하려고하면 세션이 application.html.erb에서 삭제 나는 다음과 같은 오류가 발생합니다 :

undefined local variable or method `destroy_user_session_path' for #<#<Class:0xb468e278>:0xb423e1dc> 

application.html.erb :

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
    <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> 
    <title>Coffee Tracker</title> 
    <%= stylesheet_link_tag 'application'%> 
    <!--%= stylesheet_link_tag 'scaffold' %--> 
</head> 
<!--%= javascript_include_tag :defaults %--> 
<%= javascript_include_tag 'application' %> 
<%= csrf_meta_tag %> 
...snip... 
<% if user_signed_in? %> 
    <span id="currentuser"><%= current_user.email %></span> 
    <%= link_to('Logout', destroy_user_session_path, :method => 'delete') %> 
<% else %> 

나는 또한 동일한 오류 내가 선을하려고하면

<%= link_to('Logout', destroy_user_session_path, :method => :delete) %> 

를 application.js
// Place your application-specific JavaScript functions and classes here 
// This file is automatically included by javascript_include_tag :defaults 
//= require_self 
//= require_tree . 
//= require jquery 
//= require jquery_ujs 

레일 3.2.0 루비 1.8.7 (2011-02-18 패치 레벨 334)는 i686 리눅스]

  • 레일 (3.2.0)
  • JQuery와 레일 (2.0.0)
  • 고안 (2.0.0)
  • omniauth (1.0.2)
  • omniauth - 한국어 (1.2.0)
  • omniauth-OAuth2를 (1.0.0) 01,235
  • 16,

업데이트 : 여기 인 레이크 경로 : 당신이 특정라는 이름의 경로가

+0

당신이 당신의'routes.rb'file에 변경을 할 경우, 변경 사항을 확인하기 위해 웹 서버를 다시 시작해야합니다. –

+2

레이크 루트를 수행하고 사용자 세션과 관련된 섹션을 게시 할 수 있습니까? –

답변

3

얻을 = config.sign_out_via에 삭제 모듈은 경로를 추가합니다.

응용 프로그램/모델/user.rb :

devise :omniauthable, :database_authenticatable 

레이크 경로 : 나는 그것을 확인하는 문서를 발견

 new_user_session GET /users/sign_in(.:format)    devise/sessions#new 
      user_session POST /users/sign_in(.:format)    devise/sessions#create 
    destroy_user_session DELETE /users/sign_out(.:format)    devise/sessions#destroy 
user_omniauth_callback  /users/auth/:action/callback(.:format) users/omniauth_callbacks#(?-mix:facebook) 
      coffee_list GET /coffee/list(.:format)     coffee#list 
        root  /         menu#index 
           /:controller(/:action(/:id(.:format))) :controller#:action 

는 devise_for 문서에이 노선을 만들으로 인증 사용하는 모듈을 보여줍니다 http://rubydoc.info/github/plataformatec/devise/master/ActionDispatch/Routing/Mapper#devise_for-instance_method

+1

은 사용자가 로컬 데이터베이스 (omniauth 방법과 반대)에 대해서도 인증합니까? 비슷한 설정으로 작업 중이며 database_authenticatable에 추가 기능 (https://github.com/plataformatec/devise/blob/master/lib/devise/models/database_authenticatable.rb)을 추가 할 필요가 없습니다. 모델. 그냥 경로를 수동으로 추가하는 것이 더 좋을까요? '삭제'/ users/auth/sign_out ', : to =>'사용자/세션 # 파괴 ', : as => : destroy_user_session' – twelve17

+0

실제로 가능합니다. 처음에는 로컬 또는 옴니 오스를 통해 로그인 할 수있었습니다. – Craig

1
user_session_path(current_user), :method => :delete 

내 추천 :

  1. 다음을 추가하십시오. D는 => 다음 LINK_TO
  2. 에 삭제 또는, devise.rb 파일의 라인 config.sign_out_via을 변경 = 을 : 나는 데이터베이스으로 인증 유증 누락 된
+0

destroy_user_session_path가 경로가되어야하나요? 내 문제의 일부는 내가 어디서/어떻게 생성되어야하는지 모르겠다. 그래서 그것을 고치기 위해 어디를보아야할지 모르겠다. – Craig

2

당신은 두 가지 솔루션 중 하나에이 "파괴"가 없다면

user_omniauth_callback  /users/auth/:action/callback(.:format) users/omniauth_callbacks#(?-mix:facebook) 
      coffee_list GET /coffee/list(.:format)     coffee#list 
        root /         menu#index 
          /:controller(/:action(/:id(.:format))) :controller#:action 
+1

죄송합니다. 질문에 오타가 있었으므로 : method => : delete를 시도했지만 여전히 실패했습니다. – Craig

+0

config.sign_out_via = : 시도해 봤어 devise.rb 파일에? – mohamagdy

+0

예, 경로를 추가하는 인증 가능한 모델 (예 : 내 모델에서 database_authenticatable)을 사용하지 않아 작동하지 않았습니다. – Craig

6

omniauthabledatabase_authenticatable없이 사용하려면 수동으로 경로를 추가해야합니다.

routes.rb에서 :

다음
devise_scope :user do 
    delete "https://stackoverflow.com/users/sign_out" => "devise/sessions#destroy" 
end 

보기에 :

왜 이렇게해야합니까? 여기에 호세 Valim의 이론적 근거를 참조하십시오

+0

많이 도와 줘서 고마워! – asiniy

+0

문제 없음 :) 다른 누군가가 내 투쟁에서 이익을 얻을 수있어 기쁩니다. – monozok

관련 문제