[英]Rails NameError (uninitialized constant Registration):
I am currently using Cancan and my users basically have different 'roles'. 我目前正在使用Cancan,而我的用户基本上具有不同的“角色”。 I only want people to be able to register 'consumer' user accounts and for business accounts admins will be doing that. 我只希望人们能够注册“消费者”用户帐户,而对于商业帐户,管理员将这样做。
So now, I have this in my ability.rb 所以现在,我的能力已经有了
def initialize(user)
user ||= User.new
...
# You can only create accounts that are consumers
can :create, User do |user|
user.role? :consumer
end
and in my controller/users/registrations_controller.rb 并在我的controller / users / registrations_controller.rb中
class Users::RegistrationsController < Devise::RegistrationsController
load_and_authorize_resource
end
and config/routes.rb: 和config / routes.rb:
devise_for :users, :controllers => {
:registrations => "users/registrations"
}
Now when I visit the registration page, I am seeing "uninitialized constant Registration" with NO stack trace whatsoever. 现在,当我访问注册页面时,我看到的是“未初始化的常量注册”,没有任何堆栈跟踪。 Any ideas? 有任何想法吗?
My code example 我的代码示例
class ApplicationController < ActionController::Base
authorize_resource
check_authorization
end
class Users::SessionsController < Devise::SessionsController
skip_authorize_resource
skip_authorization_check
end
For load_and_authorize_resource
you will need skip_load_and_authorize_resource
. 对于load_and_authorize_resource
您将需要skip_load_and_authorize_resource
。 And all this code is applicable for custom devise
's controller. 所有这些代码都适用于定制devise
的控制器。 Just create one. 只需创建一个。
The issue is with the routes, please follow the following steps 问题在于路线,请按照以下步骤操作
1. $ rake routes, you will see the list of routes
2. In your config/routes.rb write the route you need, In my case the route to create a new user was,
devise_for :users, :controllers => { :new_user_registration => "users/registrations#new" }
3. restart rails server
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.