title: Rails - CanCanCan - common abilities
body: <p>I am using Rails 4, devise, Role Model and CanCanCan.</p>
  
  <p>Is it possible to define an ability in ability.rb that is common to a number of roles?</p>
  
  <p>For example, every logged in user can CRUD their own profile page? And then roles have specific abilities on top of that common ability?</p>
  
  <p>How does that work? Do I need to create a role in Role Model for common abilities and then allow each user to have multiple roles, so that they get the common abilities as well as the role specific abilities?</p>
  
  <p>For example, in my ability.rb, I have:</p>
  
  <pre><code>class Ability
    include CanCan::Ability
  
    def initialize(user)
  
        alias_action :create, :read, :update, :destroy, :to =&gt; :crud
  
  
      # Define abilities for the passed in user here. For example:
      #
      user ||= User.new # guest user (not logged in)
  
        #users who are not signed in can create registration or login 
  
        # can read publicly available projects, programs and proposals
        can :read, Project, {:active =&gt; true, :closed =&gt; false, :sweep =&gt; { :disclosure =&gt; { :allusers =&gt; true } } }
  
        # {:active =&gt; true, :closed =&gt; false  &amp;&amp;  :Project.sweep.disclosure.allusers =&gt; true}
        # if user role is student
  
        if user_signed_in?
          can :crud, Profile, :user_id =&gt; user.id #[for themselves]
  
  
        elsif user.try(:profile).present? &amp;&amp; user.profile.has_role?(:student)
  </code></pre>
  
  <p>So, I want students to be able to read the same things that guests can read. Is there a way to say that students can do everything that new users and users who are signed in can do (as well as the student specific abilities)? </p>