title: How to check for a role
body: <p>I'm a rails noob and first time poster here and am using declarative authorization in order to implement role base access restriction in a small timesheet app I am writing.</p>
  
  <p>In one of my views, specifically the index.html.erb for my time_registers needs to display more information if the user who is logged in has the admin role assigned.</p>
  
  <p>In the beginning I was just checking that user would be the one with id == 1</p>
  
  <pre><code>&lt;% if @current_user.id == 1 %&gt;
  </code></pre>
  
  <p>but now I'd like to be able to not restrict it to the user with id==1 but to allow any user who has had the admin role assigned to view a bit more in the index.html.erb file.</p>
  
  <p>A bit how the model is set up with declarative_authorization</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_many :assignments
  
  class Role &lt; ActiveRecord::Base
    has_many :assignments
    has_many :users, :through =&gt; :assignment
  
  class Assignment &lt; ActiveRecord::Base
    belongs_to :user
    belongs_to :role
  </code></pre>
  
  <p>My Authorizations file looks like this:</p>
  
  <pre><code>authorization do
  
    role :usuarios do
      has_permission_on :users, :to =&gt; [:index, :show, :new, :create, :edit, :update]
    end
  
    role :reghoras do
      has_permission_on :time_registers, :to =&gt; [:index, :show, :new, :create, :edit, :update]
      has_permission_on :users do
        to :show
        if_attribute :id =&gt; is {user.id}
      end
    end
  
    role :contactos do
      has_permission_on :contacts, :to =&gt; [:index, :show, :new, :create, :edit, :update]
      has_permission_on :users do
        to :show
        if_attribute :id =&gt; is {user.id}
      end
    end
  
    role :admin do
      has_permission_on :authorization_rules, :to =&gt; :read
      has_permission_on [:time_registers, :contacts, :users, :roles], :to =&gt; [:index, :show, :new, :create, :edit, :update, :destroy]
    end
  
    role :guest do
      has_permission_on [:time_registers, :contacts], :to =&gt; [:index, :show]
    end
  
  end
  </code></pre>
  
  <p>Well, I am not sure what else would be needed to answer this question, so feel free to request more information. </p>