Ok, I solved the problem. My use case is briefly mentioned at the beginning of CanCan README, and I skipped it. You can define new skill classes in the / models / application that take a different parameter than current_user. To do this, add the following to the controller:
def current_ability if params[:controller] == 'leagues' @current_ability = LeagueAbility.new(current_user_league_relation) elsif params[:controller] == 'league_relations' @current_ability = LeagueRelationAbility.new(current_user_league_relation) else @current_ability = Ability.new(current_user) end end
Now you can create league_ability.rb in the / models / application.
class LeagueAbility include CanCan::Ability def initialize(league_relation) league_relation ||= LeagueRelation.new if league_relation.owner? can :manage, League, :id => league_relation.league_id elsif league_relation.moderator? can :manage, League, :id => league_relation.league_id cannot [:delete, :destroy], League else can :read, League can :create, League end end end
It should be noted that this depends on your application controller calling the method in the child class. Hope this helps!
Max
source share