title: Ruby loop problems
body: <p>I am working on a script that is supposed to be writing a list of items to a hash, but for some reason its only placing the last item in the loop in the hash... I have been working on this script all day, so I am pretty sure its something I am just missing.</p>
  
  <p>Here is the script</p>
  
  <pre><code>@mr = MediaRating.where("user_id = ?", session['user_credentials_id'])
  @mr.each do |rating|
    @m = Media.where("id = ?", rating.media_id)
    @m.each do |m|
      s = Profile.find_by_subscriber_id(m.subscriber_id)
      @h_lang = Language.find_by_code(s.language)
      @history = {m.title =&gt; @h_lang.english}
    end
  end
  </code></pre>
  
  <p>There are multiple records in the MediaRating table so I know it has to do something with how my loop is. Thanks in advance for the help!</p>
  
  <p>Working code:</p>
  
  <pre><code>@mr = MediaRating.where("user_id = ?", session['user_credentials_id'])
  @mr.each do |rating|
    @m = Media.find(rating.media_id)
    s = Profile.find_by_subscriber_id(@m.subscriber_id)
    @h_lang = Language.find_by_code(s.language)
    @history[@m.title] = @h_lang.english
  end
  </code></pre>