title: Rails aws-sdk cannot delete file on Amazon S3
body: <p>My code does not delete the file in my Amazon S3 bucket and I don't know why.</p>
  
  <p><strong>Logs</strong></p>
  
  <pre><code>Processing by PicturethingsController#destroy as HTML
    Parameters: {
      "authenticity_token"=&gt;"eEmuCyMmV8K3X5xp4rCozbwv8EnU6bZY3+juwBr/v8ScPCP/nbQ5+pgXWZOJkuJ3ZNrfDaNTx86ailFKjwTLCw==", 
      "picid"=&gt;"10", 
      "picture_url"=&gt;"//websmash.s3.amazonaws.com/uploads/faa8c7d2-0261-4753-9cbb-c4ea06520721/picture1.png"}
  </code></pre>
  
  <p><strong>Picturethings controller</strong></p>
  
  <pre><code>before_action :delete_picture_from_s3, only: [:destroy]
  before_action :set_s3_direct_post,  only: [:edit]
  
  def destroy
    @picturething = Picturething.find(params[:picid])
    @picturething.destroy # this works fine
    redirect_to request.referrer || root_url
  end
  
  def delete_picture_from_s3
    S3_BUCKET.object(params[:picture_url]).delete
    return true
    rescue =&gt; e
      # Do nothing. Leave the now defunct file sitting in the bucket.
      return true
  end
  
  private
  
    def set_s3_direct_post
      @s3_direct_post = S3_BUCKET.presigned_post(key: "uploads/#{SecureRandom.uuid}/${filename}", success_action_status: '201', acl: 'public-read')
    end
  </code></pre>
  
  <p><strong>picturething.rb</strong></p>
  
  <pre><code>class Picturething &lt; ActiveRecord::Base
    validates  :picture, presence: true
    .
    .
  end
  </code></pre>
  
  <p><strong>In the view</strong></p>
  
  <pre><code>&lt;%= button_to delete_picture_path(
                  params: {
                    picid:       standardpicture.id,
                    picture_url: standardpicture.picture
                  }
                ),
                class: 'btn btn-default btn-xs',
                data: { confirm: "Delete picture: are you sure?" },
                method: :delete do %&gt;
    &lt;span class="glyphicon glyphicon-remove" aria-hidden="true"&gt;&lt;/span&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p><strong>initializer</strong></p>
  
  <pre><code>Aws.config.update({
    region: 'us-east-1',
    credentials: Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY']),
  })
  S3_BUCKET = Aws::S3::Resource.new.bucket(ENV['S3_BUCKET'])
  </code></pre>
  
  <p>The rails bit works fine - the picture is deleted from the rails database no problem. But the picture remains in the amazon bucket.</p>