私はレール開発の初心者で、最初のエンジンを作成しようとしています。このエンジンは、承認とユーザーのアクセス許可の制限に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?'
私は何を間違っていますか?