title: How to pass argument to delegate method in Rails
body: <p>I would like to have a Dashboard to display summary of multiple models, and I implemented it using Presenter without its own data. I use an ActiveModel class (without data table):</p>
  
  <pre><code>class Dashboard
    attr_accessor :user_id
    def initialize(id)
      self.user_id = id
    end
  
    delegate :username, :password, :to =&gt; :user 
    delegate :address,  :to =&gt; :account
    delegate :friends,   :to =&gt; :friendship
  
  end 
  </code></pre>
  
  <p>By delegate, I want to be able to call <code>Dashboard.address</code> and get back <code>Account.find_by_user_id(Dashboard.user_id).address</code>. </p>
  
  <p>If Dashboard was an ActiveRecord class, then I could have declared <code>Dashboard#belongs_to :account</code> and delegate would work automatically (i.e., Account would know it should return address attribute from account with <code>user_id</code> equals <code>to user_id</code> in Dashboard instance). </p>
  
  <p>But Dashboard is not an ActiveRecord class, so I can't declare <code>belongs_to</code>. I need another way to tell Account to lookup the right record.</p>
  
  <p>Is there a way to overcome this problem? (I know I can fake Dashboard to have an empty table, or I can rewrite User's instance methods to class methods that take argument. But these solutions are all hacks).</p>
  
  <p>Thank you.</p>