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.