【问题标题】:Devise Signout Routing Error设计登出路由错误
【发布时间】:2011-11-26 03:22:43
【问题描述】:

我在 Rails 3.0.3 应用程序中使用 Devise 1.5.1。它运行良好,但有一个例外:登出链接给了我这个错误:

路由错误

未初始化的常量UsersController

指向此的链接是:

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

我还没有创建 app/controllers/user_controller.rb 文件,但我的理解是在使用 Devise 时这不是必需的,对吗?

如果相关,我的 routes.rb 文件如下所示:

Su::Application.routes.draw do

 get "group/create"

  devise_for :users

  resources :users
  resources :payers
  resources :payments
  resources :categories
  resources :groups

  match "adduser", :to => "groups#adduser"

  root :to => "pages#home"
end

...和 ​​app/models/user.rb 看起来像:

class User < 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 :first_name, :email, :password, :password_confirmation, :remember_me, :group_id
end

我已经在 SO 上进行了广泛的搜索和搜索,但无济于事。我应该如何解决这样的问题?

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 routing devise


    【解决方案1】:

    在你的路线文件中,你有

    devise_for :users

    为设计路线服务,但是

    资源:用户

    是一个通用的 CRUD 路由,它使 Rails 认为在您的应用程序中,您有 Users Controller,并且您正在使用模型中的用户模型做一些事情。

    错误表明您没有用户控制器,这是真的,但它正在寻找它,因为路由。
    所以,如果你想对用户模型做点什么,要么删除这一行,要么添加一个用户控制器。

    如果有任何不清楚的地方,请发表评论。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多