2

私はレール開発の初心者で、最初のエンジンを作成しようとしています。このエンジンは、承認とユーザーのアクセス許可の制限にCanCanを使用できます。

エンジンにいくつかのアクセス許可があり、それらをメイン アプリケーションに継承したいと考えています。

例えば:

app/models/my_engine/ability.rbエンジン内のファイル

module MyEngine
  class Ability
    include CanCan::Ability
    def initialize(user)
      user ||= MyEngine::User.new # guest user
      if user.role? "Admin"
        can :manage, :all
      else
        can :read, :all
      end
    end
  end
end

app/models/ability.rbメインアプリケーションのファイル

class Ability < MyEngine::Ability
  def initialize(user)
    user ||= MyEngine::User.new # guest user
    super(user)
    can :create, SomeModel if user.manager?
  end
end

ファイルapp/controllers/my_engine/application_controller.rb

module MyEngine
  class ApplicationController < ActionController::Base
    def current_ability
       @current_ability ||= MyEngine::Ability.new(current_user)
    end
  end
end

しかし、それは機能しませんcan?。エンジンでメソッドを使用すると、次のエラーが発生します。

undefined method `can?'

私は何を間違っていますか?

4

1 に答える 1

0

githubの問題に関するいくつかの議論: ryanb/cancan

于 2012-06-04T19:01:53.867 に答える