title: Rails: Loop thru two different models
body: <p>I have implemented a basic search and I'm looping thru the results like this:</p>
  
  <p>views/items/search.html.erb</p>
  
  <pre><code> &lt;% if @items.present? %&gt;
         &lt;% if @items %&gt;
           &lt;% @items.each do |item| %&gt;
               &lt;%= link_to item.title, item %&gt;
                 &lt;%= number_to_currency item.price %&gt;
             &lt;% end %&gt;
           &lt;% end %&gt;
      &lt;% end %&gt; 
  </code></pre>
  
  <p>Also I have an <code>account.rb</code> which <code>belongs_to :user</code> and contains all the  details regarding address, phone# etc. </p>
  
  <p>Model associations:</p>
  
  <pre><code>class Account &lt; ApplicationRecord
    belongs_to :user
  end
  
  class Item &lt; ApplicationRecord
    belongs_to :user
    belongs_to :account
  end
  
  class User &lt; ApplicationRecord
    has_one :account, autosave: true
    has_many :items
  end
  </code></pre>
  
  <p>Also, I have <code>t.integer "user_id"</code> under <code>accounts</code> and <code>items</code> tables as well.</p>
  
  <p>I would like to show the <code>account</code> information of the specific item on the results. How can I loop thru two different models and show the desired result?</p>