title: Rails 3 - images not rendering correctly on first page view
body: <p>In my rails3 app I've got an image gallery where:</p>
  
  <pre><code>gallery has many images
  image belongs to gallery
  </code></pre>
  
  <p>I'm using carrierwave to upload images to S3.</p>
  
  <p>My gallery page ('show' action) displays thumbnails for each image in that gallery.</p>
  
  <p>I use colorbox to display the images modally when a user clicks on the thumbnail.</p>
  
  <p>Quite often, I see this after clicking on an image:</p>
  
  <p><img src="https://internet-websites.s3.amazonaws.com/Screenshot-10.png" alt="good_image"></p>
  
  <p>what I want to see is this:</p>
  
  <p><img src="https://internet-websites.s3.amazonaws.com/Screenshot-9.png" alt="bad_image"></p>
  
  <p>I've done a LOT of troubleshooting:</p>
  
  <ul>
  <li>Tried using FancyBox instead of ColorBox - same problem</li>
  <li>Tried using different branch of CarrierWave - same problem</li>
  <li>Tried putting my images in European Buckets (I'm in Europe) - same problem</li>
  <li>Tried eager loading my images along with the gallery - same problem</li>
  <li>Tried using Google Hosted jQuery 1.4.1, and 1.4.3 - same problem</li>
  <li>Uploaded everything to Heroku - same problem</li>
  <li>Tried explicitly setting the width of my colorbox (as well as various other content divs)</li>
  <li>Edited ACL for S3 Bucket</li>
  <li>Using html5 doctype for images.html.haml (layout for images controller)</li>
  </ul>
  
  <p>This tends to <strong>the first time I click on thumbnail</strong> <em>after it has been uploaded</em> although I've noticed it happening with images I've not clicked on in over an hour or so too. The problem goes away if I click on the thumbnail again immediately after the failure.... I never have any trouble with the thumbnails, they all load fine. It seems as though the large (original) version of the image is not getting downloaded on the first attempt.  </p>
  
  <ul>
  <li>There are no errors in my logs. </li>
  <li>This is driving me absolutely NUTS. </li>
  <li>I'm using Fog gem version 0.3.13.</li>
  </ul>
  
  <p>What else can I do here?  What more troubleshooting can I try?  Any help would be appreciated. </p>
  
  <p>Here's some of my code:</p>
  
  <pre><code>class Image &lt; ActiveRecord::Base
    belongs_to :gallery
    mount_uploader :photo, ImageUploader
    attr_accessible :photo, :gallery_id
    validates_presence_of :photo
  end
  
  class Gallery &lt; ActiveRecord::Base
    default_scope order("id DESC")
    has_many :images
    attr_accessible :name, :images_attributes, :description
    accepts_nested_attributes_for :images, :reject_if =&gt; :all_blank, :allow_destroy =&gt; true
    validates_presence_of :name
  end
  
  #images/show.html.haml
  = image_tag @image.photo_url if @image.photo_url
  
  #galleries/show.html.haml
  - for image in gallery.images
    .image
      = link_to image_tag(image.photo_url(:thumb)), image_path(image), :name=&gt;"modal", :class=&gt;"group" if image.photo_url(:thumb)
  
  #layouts/images.html.haml
  !!! 5
  %html
    %body
      #image
        = yield
  </code></pre>