设计注销路由错误

时间:2011-11-26 03:22:44

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

我在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,但无济于事。我应该如何解决这类问题?

1 个答案:

答案 0 :(得分:3)

在路线文件中,您有

  

devise_for:users

用于设计Devise的路线,但

  

资源:用户

是一种通用的CRUD路由,它使Rails认为在您的应用中,您有Users Controller,并且您正在使用模型中的用户模型。

错误告诉您没有用户控制器并且这是真的,但由于路线正在寻找它。
因此,如果要对Users模型执行某些操作,请删除该行或添加用户控制器。

如果有任何不明确的地方,请将其作为评论发布。

相关问题