2014-09-03 51 views
0

我已經安裝在我的引擎裝置和後加在我application.html.erb文件中的以下內容:Rails的設計引擎SIGN_OUT鏈接錯誤

<div id="user_nav"> 
    <% if user_signed_in? %> 
     Signed in as <%= current_user.email %>. This cannot be cheese? 
     <%= link_to "Sign out", destroy_user_session_path, :method => :delete %> 
    <% else %> 
     <%= link_to 'Register', new_user_registration_path %> or <%= link_to 'Sign in', new_user_session_path %> 
    <% end %> 
</div> 

這表明No route matches "https://stackoverflow.com/users/sign_out",它顯示了

<%= link_to 'Register', new_user_registration_path %> or <%= link_to 'Sign in', new_user_session_path %> 
錯誤

錯誤消息NameError in Devise::Sessions#new

undefined local variable or method `destroy_user_session_path' for #<#<Class:0x007fb4da2e9618>:0x007fb4da2db9a0> 

瑞克路線結果

Routes for Fd::Engine: 
    users_auth_google_oauth2_callback GET  /users/auth/google_oauth2/callback(.:format) fd/omniauth_callbacks#google_oauth2 
         fd_test_index GET  /fd/test/index(.:format)      fd/fd/test#index 
fd_omniauth_callbacks_google_oauth2 GET  /fd/omniauth_callbacks/google_oauth2(.:format) fd/fd/omniauth_callbacks#google_oauth2 
        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_password POST  /users/password(.:format)      devise/passwords#create 
        new_user_password GET  /users/password/new(.:format)     devise/passwords#new 
       edit_user_password GET  /users/password/edit(.:format)     devise/passwords#edit 
            PATCH /users/password(.:format)      devise/passwords#update 
            PUT  /users/password(.:format)      devise/passwords#update 
      cancel_user_registration GET  /users/cancel(.:format)      devise/registrations#cancel 
        user_registration POST  /users(.:format)        devise/registrations#create 
       new_user_registration GET  /users/sign_up(.:format)      devise/registrations#new 
      edit_user_registration GET  /users/edit(.:format)       devise/registrations#edit 
            PATCH /users(.:format)        devise/registrations#update 
            PUT  /users(.:format)        devise/registrations#update 
            DELETE /users(.:format)        devise/registrations#destroy 
      user_omniauth_authorize GET|POST /users/auth/:provider(.:format)    omniauth_callbacks#passthru {:provider=>/google_oauth2/} 
      user_omniauth_callback GET|POST /users/auth/:action/callback(.:format)   omniauth_callbacks#(?-mix:google_oauth2) 
         fd_auth_index GET  /fd/auth/index(.:format)      fd/fd/auth#index 
           root GET /           fd/auth#index 
     omniauth_callbacks_verify_otp GET  /omniauth_callbacks/verify_otp(.:format)  fd/omniauth_callbacks#verify_otp 
    omniauth_callbacks_delete_session GET  /omniauth_callbacks/delete_session(.:format) fd/omniauth_callbacks#sign_out 

引擎路線:

Fd::Engine.routes.draw do 
devise_for :users,:controllers => { :omniauth_callbacks => "omniauth_callbacks" }, :class_name => "Fd::User", module: :devise 
end 
+0

雖然'耙routes'顯示確切的路徑,但仍然得到了錯誤,並STANGE它指向'設計: :Sessions#new' class as session not new – 2014-09-03 10:53:21

+0

問題出現在'<%= link_to「註銷」,destroy_user_session_path,:method =>:刪除%>'行而不是您發佈的內容。一切看起來不錯。 – Surya 2014-09-03 10:57:42

+0

試試這個<%= link_to user_signout_url do%>退出<% end %> – 2014-09-03 11:11:54

回答

0

您綜合OmniAuth在設計,所以如果用戶提供了正確的憑據設計將創建會話,從你的問題我理解會話創建成功,所以如果你想清楚會議剛剛創建的控制器(你啓動會話)一個動作,並給

redirect_to "https://stackoverflow.com/users/sign_out" 

嘗試

redirect_to destroy_user_session_path 

我希望這將工作

+0

謝謝Ram第一選項工作。 – 2014-09-04 08:20:36

0

試試這個:

<%= link_to "Sign out", destroy_user_session_path, :method => :get %> 

,並確保你有下面一行在你config/initializers/devise.rb

config.sign_out_via = :get 
+0

它顯示相同的錯誤「未定義的局部變量或方法'destroy_user_session_path'...」 – 2014-09-03 12:02:33

+0

並且還確保您已定義devise_for:routes.rb用戶 – VDN 2014-09-03 12:07:29

+0

添加devise_for:用戶routes.rb並檢查它應該工作.. – VDN 2014-09-03 12:11:18