[英]Rails NameError (uninitialized constant Registration):
我目前正在使用Cancan,而我的用戶基本上具有不同的“角色”。 我只希望人們能夠注冊“消費者”用戶帳戶,而對於商業帳戶,管理員將這樣做。
所以現在,我的能力已經有了
def initialize(user)
user ||= User.new
...
# You can only create accounts that are consumers
can :create, User do |user|
user.role? :consumer
end
並在我的controller / users / registrations_controller.rb中
class Users::RegistrationsController < Devise::RegistrationsController
load_and_authorize_resource
end
和config / routes.rb:
devise_for :users, :controllers => {
:registrations => "users/registrations"
}
現在,當我訪問注冊頁面時,我看到的是“未初始化的常量注冊”,沒有任何堆棧跟蹤。 有任何想法嗎?
我的代碼示例
class ApplicationController < ActionController::Base
authorize_resource
check_authorization
end
class Users::SessionsController < Devise::SessionsController
skip_authorize_resource
skip_authorization_check
end
對於load_and_authorize_resource
您將需要skip_load_and_authorize_resource
。 所有這些代碼都適用於定制devise
的控制器。 只需創建一個。
問題在於路線,請按照以下步驟操作
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.