2
我是rails開發新手,我試圖創建我的第一個引擎。該引擎可以使用CanCan進行授權並限制用戶的權限。在引擎中使用CanCan。 Ability.rb示例
我在我的引擎中有一些權限,我想在我的主應用程序中繼承它們。
例如:
文件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?'
我在做什麼錯?