title: Rails how to implement role and define role's power?
body: <p>Now, in my rails app, I use simple authentication(email, password) and give account <code>role</code> to define what account can do.</p>
  
  <pre><code>  def login
      email = params[:email]
      @account = Account.find_by_email(email)
      if @account &amp;&amp; @account.authenticate(params[:password])
        session[:user_id] = @account.id
        redirect_to books_path
      else
        render :login
      end
    end
  
  def current_user
      @current_user ||= Account.find(session[:user_id]) if session[:user_id]
  end
  </code></pre>
  
  <p>for example: two role manager(role_id:1) and user(role_id:2...N)
  in controller, I use stupid way to set data for each role like:</p>
  
  <p><strong>every book has account_id</strong></p>
  
  <pre><code>def index
      @books = Book.where("account_id = ?,@current_user.id)
      @books = Book.all if @current_user.role_id == 1
  end
  </code></pre>
  
  <p>it seems so foolish, and I tried to use <strong>cancancan</strong> to solved this, but as I know, <strong>cancancan</strong> just can define for Restful method, and can distinguish role authority like manager can do all and method can do show... does <strong>cancancan</strong> can do some way to solved what role can see what data they own? use <strong>cancancan</strong> or other way to solved? please give me some advice! thanks.</p>