2011-08-06 5 views
1

현재 Cancan을 사용하고 있으며 사용자는 기본적으로 서로 다른 '역할'을 가지고 있습니다. 나는 사람들이 '소비자'사용자 계정을 등록 할 수 있기를 바랄 뿐이며 비즈니스 계정 관리자는이를 수행 할 것입니다.레일 NameError (초기화되지 않은 상수 등록) :

그래서 지금은

class Users::RegistrationsController < Devise::RegistrationsController 
    load_and_authorize_resource 
end 

및 설정/routes.rb 내 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 

과 내 컨트롤러/사용자/registrations_controller.rb이 있습니다

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

등록 페이지를 방문하면 스택 추적 없음으로 "초기화되지 않은 상수 등록"이 표시됩니다. . 어떤 아이디어?

+0

를 따르십시오인가? –

+0

행운이 해결? – ZMorek

답변

0

내 코드 예제

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의 컨트롤러에 적용됩니다. 그냥 하나 만들어.

0

문제는 당신이 문제가 사라지지 않는`ability.rb`에서 선을 제거하면 경로로, 다음 단계

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 
관련 문제