[英]Rails Devise Error “No route matches [GET] ”/users/sign_out“”
[英]Devise routes issue in Rails 3.1 with No route matches [GET] “/users/sign_out”
我在我的Rails 3.1應用程序中使用了Devise 1.4.9身份驗證gem,當我單擊任何鏈接時,都會出現路由錯誤。 單擊“注銷”鏈接時,將發生以下情況:
Routing Error
No route matches [GET] "/users/sign_out"
我正在使用此方法創建鏈接:
<%= link_to('Sign Out', destroy_user_session_path, :method => :delete) %>
這是鏈接在源中的呈現方式:
<a href="/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"}
我已經嘗試了該線程中的幾乎所有內容,但都沒有成功:
沒有路線匹配“ / users / sign_out”設計導軌3
我已經多次重啟服務器。
這個問題似乎在過去出現過,但是沒有一個描述的解決方案改變了這種行為,對此我感到很困惑。
寫作
devise_scope :user do
get "/users/sign_out", :to => "devise/sessions#destroy"
end
在我的routes.rb
為我解決了這個問題。
一種,您可能希望使用按鈕(可以將其樣式化為看起來像鏈接)來破壞性,如使用GET
此清單所示 。 僅此一項就可以解決。
第二,您需要文件中的csrf_meta_tag
,您可能已經擁有了。
您是否已確認JS文件實際上已被加載?
(我認為帶空格的// =
可能是個問題,但顯然它的效果和Rails默認創建的//=
一樣。)
如果將:defaults
傳遞給javascript_include_tag
,請嘗試將:defaults
重命名為:application
,以防您在application.js
定義包含內容
<%= javascript_include_tag :application %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.