2012-08-17 120 views
0

在我的Rails應用程序中,註銷鏈接無法正常工作,我不知道我能做些什麼來解決它。在我的Heroku的日誌,當我嘗試從我的用戶帳戶signout,我得到以下錯誤:我該如何解決這個路由錯誤?

的ActionController :: RoutingError(無路由匹配[GET] 「/ signout」):

我有以下在我的配置路徑/文件的routes.rb:

match '/signout', to: 'sessions#destroy', via: :delete 

而在我的會話控制器我有以下方法:

def destroy 
    sign_out 
    redirect_to root_path 
end 

然後在我的session_shelper.rb文件我有後續荷蘭國際集團SIGN_OUT方法:

def sign_out 
    self.current_user = nil 
    cookies.delete(:remember_token) 
    end 

一切似乎是正確的從我的角度,所以我不知道是什麼原因造成的錯誤,或者我怎麼能解決這個問題。如果有幫助,我的應用程序託管在Heroku上。非常感謝!

sessions_controller.rb

class SessionsController < ApplicationController 

    def new 
    end 

    def create 
    user = User.find_by_email(params[:session][:email]) 
    if user && user.authenticate(params[:session][:password]) 
     sign_in user 
     redirect_to info_path 
    else 
     flash.now[:error] = 'Invalid email/password combination' 
     render 'new' 
    end 
    end 

    def destroy 
    sign_out 
    redirect_to root_path 
    end 

end 


      <nav> 
      <ul class="nav pull-right"> 
      <% if signed_in? %> 
       <li><%= link_to "Settings", edit_user_path(current_user) %></li> 
        <li class="divider"></li> 
       <li><%= link_to "Sign out", signout_path, method: "delete" %></li> 
      </ul> 
      <% else %> 
       <li><%= link_to "Sign in", signin_path %> 
      <% end %> 
      </ul> 
     </nav> 

回答

1

變化

match '/signout', to: 'sessions#destroy', via: :delete 

match '/signout' => 'sessions#destroy', :via => :delete 

變化

method: "delete":method => :delete

+0

好的,讓我試試這個解決方案。非常感謝你! – user1483441 2012-08-17 16:54:27

+0

@ user1483441你使用的是什麼版本的導軌?,我編輯答案的方式。 – user1455116 2012-08-17 16:56:10

+0

它沒有工作。我仍然遇到同樣的錯誤。 – user1483441 2012-08-17 16:59:26

相關問題