title: rails carrierwave edit/update form
body: <p>In my rails project I use Carrierwave to upload images to S3 via fog. So far I have the Create Read and Delete portions of the CRUD spectrum working.</p>
  
  <p>My problem is the edit/update portion. Im use the same <code>_form.html.erb</code> to edit that I used for creating records. When I click the edit link the form loads all of my data into the form fields for editing with the exception of the image.  The form field is blank as though there is no image associated with the record.</p>
  
  <p>How do I update an image that is already saved to S3?</p>
  
  <p><strong>Models/listing.rb</strong></p>
  
  <pre><code>class Listing &lt; ActiveRecord::Base
    attr_accessible :body, :price, :title, :image
  
    mount_uploader :image, ListingUploader
  end
  </code></pre>
  
  <p><strong>Controllers/listings_controller.rb</strong> (edit/update portion)</p>
  
  <pre><code>def edit
      @listing = Listing.find(params[:id])
  end
  
  def update
      @listing = Listing.find(params[:id])
      if @listing.update_attributes(params [:listing])
          redirect_to :action =&gt; 'show', :id =&gt; @listing
      else
          render :action =&gt; 'edit'
      end
  end
  </code></pre>
  
  <p><strong>_form.html.erb</strong></p>
  
  <pre><code>&lt;%= form_for @listing, :html =&gt; { :multipart =&gt; true } do |l| %&gt;
  &lt;p&gt;
      &lt;%= l.label :title %&gt;
      &lt;%= l.text_field :title %&gt;
  &lt;/p&gt;
  
  &lt;p&gt;
      &lt;%= l.label :price %&gt;
      &lt;%= l.text_field :price %&gt;
  &lt;/p&gt;
  
  &lt;p&gt;
      &lt;label&gt;Upload a Picture&lt;/label&gt;
      &lt;%= l.file_field :image %&gt;
      &lt;%= l.hidden_field :image_cache %&gt;
  &lt;/p&gt;
  &lt;div class="image-pre"&gt;
      &lt;%= image_tag(@listing.image_url(:thumb)) if @listing.image? %&gt;
  &lt;/div&gt;
  
  &lt;p&gt;
      &lt;%= l.label :body %&gt;
      &lt;%= l.text_area :body, :class =&gt; "tinymce" %&gt;
      &lt;%= tinymce %&gt;
  &lt;/p&gt;
  
  &lt;%= l.submit %&gt;
  &lt;% end %&gt;
  </code></pre>