Home:ALL Converter>Can Can for Rails Association

Can Can for Rails Association

Ask Time:2012-12-13T19:09:00         Author:Sai

Json Formatter

I used can-can gem for managing the roles in my application.

The models are as follows

class User < ActiveRecord::Base  
  has_many :projects  
  has_and_belongs_to_many :teams  
end

class Project < ActiveRecord::Base  
  belongs_to :user  
  has_many :tasks  
end

class Tasks < ActiveRecord::Base  
  belongs_to :project  
end

class Ability  
  include CanCan::Ability  

  def initialize user  
    user ||= User.new  
    if user.team? :project_manger  
        can :access, :projects,:user_id => user.id  
    else  
        can :access, :all  
    end  
  end  
end

So, now my question is how I can manage tasks that are associated with a project for the User.

Author:Sai,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/13858546/can-can-for-rails-association
yy