2014-09-03 49 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