2011-11-12 56 views
1

我正在使用Devise 1.4.9認證gem與我的Rails 3.1應用程序,當我點擊任何鏈接時,我得到路由錯誤。下面是當我點擊退出鏈接上會發生什麼:在Rails 3.1中設計路由問題,沒有路由匹配[GET]「/ users/sign_out」

Routing Error 

No route matches [GET] "https://stackoverflow.com/users/sign_out" 

我創造這個方法的鏈接:

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

這是鏈接是如何在源渲染:

<a href="https://stackoverflow.com/users/sign_out" data-method="delete" rel="nofollow">Sign Out</a> 

我有這條線在我的佈局標題:

<%= javascript_include_tag :defaults %> 

這些生產線都在我的application.js文件:

// 
// = require jquery 
// = require jquery_ujs 
// = require_tree . 

下面是相關耙路輸出:

  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"} 

我試圖在這個線程無濟於事幾乎一切:

No route matches "/users/sign_out" devise rails 3

我已重新啓動服務器多次。

這個問題似乎已經出現在過去,但沒有一個單一的解決方案描述改變了這種行爲,我很難過。

+1

hey @wrburgess你可以檢查一下,看看你的gemfile中是否有'gem'jquery-rails' '。我也很好奇,如果你可以在瀏覽器中檢查你的源代碼,並檢查是否包含jquery_ujs。您應該看到類似於: '' –

+0

我確實已經加載了該寶石,但腳本沒有。 ..可能是問題 – wrburgess

回答

0

請嘗試重命名:defaults:application的情況下,它傳遞給javascript_include_tag時您可以在定義包括application.js

<%= javascript_include_tag :application %> 
+0

是的,這是問題,這固定它。謝謝 – wrburgess

0

一,你可能想要使用一個按鈕(可以看起來像一個鏈接樣式)的東西破壞性的,根據this checklist for using GET。這可以解決它。

二,您需要文件中的csrf_meta_tag,您可能已擁有該文件。

您確認JS文件實際上是否正在加載?

(我認爲// =與空間可能是一個問題,但顯然它是Rails的默認創建工程,以及//=。)

+0

在我的頭文件中似乎沒有東西,所以我要看一下JS問題。 – wrburgess

0

寫作

devise_scope :user do 
    get "https://stackoverflow.com/users/sign_out", :to => "devise/sessions#destroy" 
    end 

在我的routes.rb爲我解決了這個問題。

相關問題