gpt4 book ai didi

authentication - 没有路由匹配 [GET] "/users/sign_out"

转载 作者:行者123 更新时间:2023-12-03 10:17:23 28 4
gpt4 key购买 nike

这是我的实际错误:No route matches [GET] "/members/sign_out"由于大多数人会使用“用户”,我认为在标题中包含它会更有帮助。无论如何,我根本无法登出。我可以成功编辑我的成员(member)资料。

我正在使用设计 1.4.2 和 Rails 3.1.0.rc4。此外,我生成了两个单独的设计模型 - 一个称为“成员”,另一个称为“管理员”。我能够通过手动导航到正确的 URL 路径(即 localhost:3000/admins/sign_in/)来注册和登录它们(同时)。我按照这个 RailsCast on Devise 在我的 application.html.haml 布局文件中创建了一些链接.我知道它只解决“成员”的登录/注销链接。

如果我单击注销链接,则会出现上述错误。如果我手动导航到任一注销 URL(即 localhost:3000/admins/sign_out/),就会发生这种情况。

有人能告诉我为什么会这样吗?以下是各种相关文件。当然,我是新手...

耙路线输出:

    j(film_repo)$ rake routes
new_member_session GET /members/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
member_session POST /members/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_member_session DELETE /members/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
member_password POST /members/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_member_password GET /members/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_member_password GET /members/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /members/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_member_registration GET /members/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
member_registration POST /members(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_member_registration GET /members/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_member_registration GET /members/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /members(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /members(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
new_admin_session GET /admins/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
admin_session POST /admins/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_admin_session DELETE /admins/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
admin_password POST /admins/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_admin_password GET /admins/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_admin_password GET /admins/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /admins/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_admin_registration GET /admins/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
admin_registration POST /admins(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_admin_registration GET /admins/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_admin_registration GET /admins/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /admins(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /admins(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
films GET /films(.:format) {:action=>"index", :controller=>"films"}
POST /films(.:format) {:action=>"create", :controller=>"films"}
new_film GET /films/new(.:format) {:action=>"new", :controller=>"films"}
edit_film GET /films/:id/edit(.:format) {:action=>"edit", :controller=>"films"}
film GET /films/:id(.:format) {:action=>"show", :controller=>"films"}
PUT /films/:id(.:format) {:action=>"update", :controller=>"films"}
DELETE /films/:id(.:format) {:action=>"destroy", :controller=>"films"}
root / {:controller=>"films", :action=>"index"}

路由文件
FilmRepo::Application.routes.draw do
devise_for :members

devise_for :admins

resources :films

root :to => 'films#index'
end

admin.rb(模型)
class Admin < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, and :omniauthable
devise :database_authenticatable, :registerable, :timeoutable,
:recoverable, :rememberable, :trackable, :validatable

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
end

member.rb(模型)
class Member < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
end

应用程序.html.haml
!!!
%html
%head
%title Film Repo
= stylesheet_link_tag 'compiled/screen.css', :media => 'screen, projection'
= stylesheet_link_tag 'compiled/print.css', :media => 'print'
/[if lt IE 8]
= stylesheet_link_tag 'compiled/ie.css', :media => 'screen, projection'
= csrf_meta_tag
%body.bp
#container
#user_nav
- if member_signed_in?
Signed in as #{current_member.email}. Not you?
\#{link_to "Sign out", destroy_member_session_path}
- else
= link_to "Sign up", new_member_registration_path
or #{link_to "sign in", new_member_session_path}
- flash.each do |name, msg|
= content_tag :div, msg, :id => "flash_#{name}"
= yield

最佳答案

我有一个类似的问题,但是添加 :method=> :delete 没有用。
我能够通过注释掉 devise_for :users 并添加为 get 请求添加新路由

devise_for :users do
get '/users/sign_out' => 'devise/sessions#destroy'
end

关于authentication - 没有路由匹配 [GET] "/users/sign_out",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6567863/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com