新手问题 devise 登出的问题

sanvi · 2012年09月11日 · 最后由 sanivbyfish 回复于 2012年09月11日 · 3428 次阅读

Routing Error

uninitialized constant AccountsController Try running rake routes for more information on available routes.

<%= render_list :class => "dropdown-menu" do |li| li << link_to("登出", destroy_account_session_path, :method => "delete") end %>

我已经尝试在 method 里面加入了 delete 了 这个是我的路由 new_account_session GET /accounts/sign_in(.:format) devise/sessions#new account_session POST /accounts/sign_in(.:format) devise/sessions#create destroy_account_session DELETE /accounts/sign_out(.:format) devise/sessions#destroy account_password POST /accounts/password(.:format) devise/passwords#create new_account_password GET /accounts/password/new(.:format) devise/passwords#new edit_account_password GET /accounts/password/edit(.:format) devise/passwords#edit PUT /accounts/password(.:format) devise/passwords#update cancel_account_registration GET /accounts/cancel(.:format) devise/registrations#cancel account_registration POST /accounts(.:format) devise/registrations#create new_account_registration GET /accounts/sign_up(.:format) devise/registrations#new edit_account_registration GET /accounts/edit(.:format) devise/registrations#edit PUT /accounts(.:format) devise/registrations#update DELETE /accounts(.:format) devise/registrations#destroy

我试过建立一个 controller 继承 Devise::RegistrationsController 但会出现其他错误

destroy_account_session_path 应该是 account_session_path

在 config 的 devise.rb 中找到一行,修改成 get # The default HTTP method used to sign out a resource. Default is :delete. config.sign_out_via = :get

刚查了下请求,发现怎么发都是 get,我已经申明了是 delete 了,太诡异了

你可以尝试下不放在 bootstrap 的 dropdown-menu 下看看能不能正常退出……

#4 楼 @wuwx 没关系的,我直接访问 url 也是,现在貌似可以了又

#5 楼 @sanivbyfish 我之前把退出的操作放在 dropdown-menu 下,结果发现那个链接的 :method => :delete 是无效的,也就是他会去请求 :get 的操作

#6 楼 @wuwx 对的,不过我改了 config 后又改回来他又工作了

需要 登录 后方可回复, 如果你还没有账号请 注册新账号