我试图覆盖默认色器件注册控制器的一些功能,以便只有特定的用户可以创建其他帐户。因此,在控制器下的文件名为registrations_controller.rb / Users文件夹,我有以下
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:用户:控制器=> {:注册=> '用户/注册'}
当我尝试去用户/ sign_up网址我得到一个路由错误“未初始化的常数用户:: RegistrationsController”。
那么,什么是真正weirding我走出这个是我曾在一个轨道中使用几乎一模一样的功能应用3没有问题。我看了一下其他一些stackoveflow类似这样的问题,我仍然没有收获。我现在正在创建的应用程序是一个轨道3.1应用程序,我使用的设计1.5.1
下面是有关其路由情况下,他们有用
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"}
我会说,有什么不对你的文件名。
您的文件应该被称为users/registrations_controller.rb
这对我行得通。
在哪里你registrations_controller.rb
保存?该位置是非常重要的。我发现我犯了一个错误保存它app/controllers/devise/.
。它只是需要被保存在app/controllers/.
例如为:
app/controllers/registrations_controller.rb
此外,config/routes.rb
路线应该被定义为:
devise_for :users, controllers: { registrations: 'registrations' }
我想,你把这里的相同的设置,但它为我工作。我上传的application到github上(我上传的日志一样,所以你可以看到,它果然奏效)。
仔细检查可能的拼写错误。也许你忘了复数或有一个类名称的拼写错误。
您好我最近刚添加姓氏和名字我的注册。我使用Rails 4。
我用下面的指令/教程完成这件事:
http://www.jacopretorius.net/2014/03/adding-custom-fields-to-your-devise-user-model-in-rails-4.html。
:)
如果你已经生成视图移动视图文件
我假设你已经在使用的轨道产生色器件:观点产生的设计意见。移动视图/设计/注册文件夹视图/用户,我想你也应该改变的形式_path
做rails routes
并检查您的航线config/routes
你可能在你的路由一个错字。
相反registrationS#new
的,你可能有别的像registration#new
。