ruby - Using CanCan in engines. Ability.rb example -


i'm new in rails development, , i'm trying create first engine. engine use cancan authorization , restricting user's permissions.

i have permissions in engine, , want inherit them in main application.

for example:

file app/models/my_engine/ability.rb in 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 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 

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 doesn't work - error if use method can? in engine:

undefined method `can?' 

what doing wrong?

some discussion on github issue: ryanb/cancan


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -