设计注销路由错误 [英] Devise Signout Routing Error

查看:162
本文介绍了设计注销路由错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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 

getgroup / create

devise_for:users

资源:用户
资源:付款人
资源:付款
资源:类别
资源:组

匹配adduser,:to = > group#adduser

root:to => page#home
end

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

  class User< ActiveRecord :: Base 
#包含默认设计模块。其他可用的是:
#:token_authenticatable,:encryptable,:confirmable,:lockable,:timeoutable和:omniauthable
devise:database_authenticatable,:可注册,
:可恢复,可记忆, :validatable

#模型的可访问(或保护)属性
attr_accessible:first_name,:email,:password,:password_confirmation,:remember_me,group_id
end

我已经在谷歌搜索和广泛搜索,但无济于事。我应该如何解决这个问题?

解决方案

在你的路由文件中,你有


devise_for:users


为Devise的路线服务,但


资源:用户


是一个通用CRUD路由,这使得Rails认为在您的应用程序中,您具有 Users Controller ,并且您正在使用模型中的Users模型进行操作。



错误告诉您没有用户控制器,这是真的,但它正在寻找它,因为路由。

所以,要删除该行或添加一个用户控制器,如果你想做一些与用户模型。



如果有什么不清楚,请发表评论。


I'm using Devise 1.5.1 in a Rails 3.0.3 app. It works well, with one exception: The signout link gives me this error:

Routing Error

uninitialized constant UsersController

The link that leads to this is:

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

I haven't created an app/controllers/user_controller.rb file, but my understanding that this wasn't necessary when using Devise, correct?

In case it's relevant, my routes.rb file looks like:

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

...and app/models/user.rb looks like:

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

I have googled and searched on SO extensively, but to no avail. How should I troubleshoot something like this?

解决方案

In your routes file, you have

devise_for :users

which serves for the routes for Devise, but

resources :users

is a generic CRUD route, which makes Rails to think that in your app, you have Users Controller, and that you are doing something with the Users model in your model.

The error tells that you don't have a Users Controller and that's true, but it's looking for it because of the route.
So, either delete the line or add a Users Controller if you want to do something with the Users model.

If anything is not clear, post it as a comment.

这篇关于设计注销路由错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆