设计重写注册控制器 - 未初始化的常量用户::注册控制器 [英] devise overriding registrations controller - uninitialized constant Users::RegistrationsController

查看:122
本文介绍了设计重写注册控制器 - 未初始化的常量用户::注册控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图覆盖默认设计注册控制器的一些功能,以便只有某些用户可以为其他用户创建帐户。所以在controller / users文件夹下的一个名为registrations_controller.rb的文件中,我有以下

I'm trying to override some the functionality of the default devise registrations controller so that only certain users can create accounts for others. So in a file called registrations_controller.rb under the controllers/users folder I have the following

class Users::RegistrationsController < Devise::RegistrationsController

  before_filter :check_permissions, :only => [:new, :create, :cancel]
  skip_before_filter :require_no_authentication

  def check_permissions
    authorize! :create, resource
  end
end

在我的路由文件中

devise_for:users,:controllers => {:registrations =>'users / registrations'}

devise_for :users, :controllers => { :registrations => 'users/registrations' }

我尝试去用户/ sign_up url我得到一个路由错误'未初始化的常量用户::注册控制器'。

When I try to go to the users/sign_up url I get a a routing error 'uninitialized constant Users::RegistrationsController'.

所以我真的很奇怪的是,我在rails 3应用程序中使用了几乎完全相同的功能,没有问题。我看了一些与此相似的其他stackoveflow问题,我还是没有更聪明。我正在建立的应用程序是一个rails 3.1应用程序,我正在使用devise 1.5.1

So what is really weirding me out about this is that I had used pretty much exactly the same functionality in a rails 3 app without a problem. I had a look at some of the other stackoveflow questions similar to this and I'm still none the wiser. The app I'm building now is a rails 3.1 app and I'm using devise 1.5.1

以下是相关路线,它们是有用的

Here are the relevant routes it case they useful

new_user_session GET    /users/sign_in(.:format)                                      {:action=>"new", :controller=>"devise/sessions"}
                         user_session POST   /users/sign_in(.:format)                                    {:action=>"create", :controller=>"devise/sessions"}
                 destroy_user_session DELETE /users/sign_out(.:format)                                   {:action=>"destroy", :controller=>"devise/sessions"}
                        user_password POST   /users/password(.:format)                                   {:action=>"create", :controller=>"devise/passwords"}
                    new_user_password GET    /users/password/new(.:format)                               {:action=>"new", :controller=>"devise/passwords"}
                   edit_user_password GET    /users/password/edit(.:format)                              {:action=>"edit", :controller=>"devise/passwords"}
                                      PUT    /users/password(.:format)                                   {:action=>"update", :controller=>"devise/passwords"}
             cancel_user_registration GET    /users/cancel(.:format)                                     {:action=>"cancel", :controller=>"users/registrations"}
                    user_registration POST   /users(.:format)                                            {:action=>"create", :controller=>"users/registrations"}
                new_user_registration GET    /users/sign_up(.:format)                                    {:action=>"new", :controller=>"users/registrations"}
               edit_user_registration GET    /users/edit(.:format)                                       {:action=>"edit", :controller=>"users/registrations"}
                                      PUT    /users(.:format)                                            {:action=>"update", :controller=>"users/registrations"}
                                      DELETE /users(.:format)                                            {:action=>"destroy", :controller=>"users/registrations"}


推荐答案

我会说,你的文件名有问题。

I would say, there's something wrong at your filename.

你的文件应该叫用户/ registrations_controller.rb

Your file should be called users/registrations_controller.rb

这对我有用。

这篇关于设计重写注册控制器 - 未初始化的常量用户::注册控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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