title: how to loop through a collection and find something in rails
body: <p>I am new to rails and ruby.</p>
  
  <p>I have a has_many association between user and store</p>
  
  <p>below is what I do:</p>
  
  <pre><code>@user = User.find_by_userid_and_password("someuser", "12345")
  =&gt; #&lt;User id: 1, userid: "someuser", password: "12345", 
  created_at: "2010-01-25 00:00:00", updated_at: "2010-01-25 00:00:00"&gt; 
  @user.stores
  =&gt; [#&lt;Store id: 3, store_id: 3, store_name: "New Store 2", 
  created_at: "2010-01-25 00:00:00", updated_at: "2010-01-25 00:00:00"&gt;, 
   #&lt;Store id: 5, store_id: 5, store_name: "Store 14th and M", 
   created_at: "2010-01-25 00:00:00", updated_at: "2010-01-25 00:00:00"&gt;]
  </code></pre>
  
  <p>so basically i am first authenticating the user and then getting all the stores that a user belongs to. For that I get a list back.  In that list of hashes i want to find out if anything is there with <code>store_id == 4</code>. </p>
  
  <p>sequentially I do:</p>
  
  <pre><code>@user.stores.first.store_id==4
  false
  @user.stores.second.store_id==4
  false
  </code></pre>
  
  <p>how can i make this in a loop? and is there any better way to do this. </p>