Ruby on rails 3.1 设计覆盖注册控制器-未初始化常量用户::注册控制器

Ruby on rails 3.1 设计覆盖注册控制器-未初始化常量用户::注册控制器,ruby-on-rails-3.1,devise,Ruby On Rails 3.1,Devise,我试图覆盖默认Desive registrations控制器的一些功能,以便只有某些用户可以为其他用户创建帐户。因此,在controllers/users文件夹下名为registrations_controller.rb的文件中,我有以下内容 class Users::RegistrationsController < Devise::RegistrationsController before_filter :check_permissions, :only => [:new

我试图覆盖默认Desive registrations控制器的一些功能,以便只有某些用户可以为其他用户创建帐户。因此,在controllers/users文件夹下名为registrations_controller.rb的文件中,我有以下内容

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

我尝试了你放在这里的相同设置,但它对我有效。我将日志上传到github(我也上传了日志,所以您可以看到它确实有效)


仔细检查可能的打字错误。也许你忘了复数,或者类名有拼写错误

我想说,你的文件名有问题

您的文件应称为
users/registrations\u controller.rb


这对我很有用。

您的
注册\u controller.rb
保存到哪里了?位置很重要。我发现我把它保存到
app/controllers/designe/
时出错了。只需将其保存在
app/controllers/
中即可,例如:

app/controllers/registrations\u controller.rb


此外,
config/routes.rb
route应定义为:


design_for:users,controller:{registrations:'registrations'}

您好,我最近在注册中添加了名字和姓氏。我使用的是Rails 4

我使用了以下说明/教程来完成此操作:


:)

如果已生成视图,请移动视图文件

我假设您已经使用rails生成设备:视图生成设备视图。将视图/设计/注册文件夹移动到视图/用户
,我认为您还应该更改表单中的路径

Do
rails routes
,并在
config/routes
中检查您的路由。您的路由可能有输入错误


您可以使用类似于
registration#new
的内容,而不是
registration#new

谢谢您举了这个例子。这真的很奇怪,我似乎有完全相同的设置,你,但我仍然得到未初始化的常数错误。我会继续寻找打字错误我也有同样的问题,结果也是我的打字错误。检查
design\u scope:user
in
config/routes.rb
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"}