Topic: Using CanCan in engines. Ability.rb example

Hi all.
I'm new in rails development, and trying create my first engine. This engine could use CanCan for authorization and restricting user's permissions.
I have some permissions in my engine and I want to inherit them in my main application.

For example:

#File app/models/my_engine/ability.rb in my engine
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
# File app/models/ability.rb in my main application
class Ability < MyEngine::Ability
  def initialize(user)
    user ||= MyEngine::User.new # guest user
    super(user)
    can :create, SomeModel if user.manager?
  end  
end

And my ApplicationController.rb in engine looks like:

# File 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

But that doesn't working, error is "undefined method `can?'", if I use method can? in engine.
What wrong I'm doing?

P.S. Sorry for my English)

Last edited by vpolotskiy (2012-06-04 11:48:56)