title: Accessing an external table from a Rails application
body: <pre><code>Rails 3.2
  </code></pre>
  
  <p>I am using the API gem. What the client wants, is to keep the table where he wants to whitelist the email addresses that can be used to access the API, in a seprate table, that he only can access through phpmyadmin.</p>
  
  <p>This would be a single table:</p>
  
  <pre><code>api_users
  </code></pre>
  
  <p>With a single column: email (in addition to id, created_at, updated_at) </p>
  
  <p>The email addresses that would go in this table, also exist in the users table for the rails application.</p>
  
  <p>If I create a model: models/api_user.rb:</p>
  
  <pre><code>class ApiUser&lt; ActiveRecord::Base
    attr_accessible :email
  </code></pre>
  
  <p>And, in my models/api_ability.rb, I add the following:</p>
  
  <pre><code>class ApiAbility
    include CanCan::Ability
  
    def initialize(user, params = {})
      user ||= User.new   
      if ApiUser.find_by_email(user.email)
        can :manage, :api
      end
    end
  
  end
  </code></pre>
  
  <p>Will this work? </p>