2011-08-06 41 views
1

私は現在Cancanを使用しており、ユーザーは基本的に異なる '役割'を持っています。 私は、「消費者」のユーザーアカウントを登録できるようにしたいと思っています。ビジネスアカウントでは、管理者がそれを実行します。Rails NameError(初期化されていない定数の登録):

はだから今、私は

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

とのconfig/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 
関連する問題