title: How to configure Rails 5, paperclip 5, aws-sdk 2 on heroku properly?
body: <p>I deployed Rails 5 app local with paperclip attachments: all was working fine. Only on heroku I need AWS s3 and it does not work with Rails 5.0.1/paperclip 5.1.0/aws-sdk 2.7.3.</p>
  
  <p>Has anybody a working configuration for storing attachments on s3?</p>
  
  <p>This is my models/article.rb:</p>
  
  <pre><code>class Article &lt; ApplicationRecord
    has_many :comments, dependent: :destroy
    validates :title, presence: true,
                  length: { minimum: 5 }
    has_attached_file :attachment,
              :url =&gt; ":s3_domain_url",
              #:path =&gt; ':filename',
              :storage =&gt; :s3,
              :bucket =&gt; ENV['AWS_BUCKET'],
              :s3_bucket =&gt; ENV['AWS_BUCKET'],
              :s3_permissions =&gt; :private,
              :s3_protocol =&gt; 'http',
              :s3_host_name =&gt; 's3.amazonaws.com',
              #:s3_host_alias =&gt; 's3.amazonaws.com',
              :s3_region =&gt; ENV['AWS_REGION'],
              #:region =&gt; ENV['AWS_REGION'],
              :s3_credentials =&gt; { :access_key_id =&gt; ENV['AWS_ACCESS_KEY_ID'],
                                   :secret_access_key =&gt; ENV['AWS_SECRET_KEY_ID'],
                                   :endpoint =&gt; 's3.amazonaws.com' }
  
    # Explicitly do not validate
    do_not_validate_attachment_file_type :attachment
    #validates_attachment :attachment, content_type: { content_type: 'application/x-java-archive'}, size: { in: 0..10.megabytes }
  end
  </code></pre>
  
  <p>The environment variables are set to:</p>
  
  <pre><code>AWS_ACCESS_KEY_ID=....
  AWS_BUCKET=....
  AWS_REGION=us-east-1
  AWS_SECRET_KEY_ID=....
  </code></pre>
  
  <p>The articles_controller is:</p>
  
  <pre><code>class ArticlesController &lt; ApplicationController
  
    http_basic_authenticate_with name: "gerrit", password: "_tVo1I44iyLe", except: [:index, :show]
  
    def index
      @articles = Article.all
    end
  
    def show
      @article = Article.find(params[:id])
    end
  
  
  
  def new
    @article = Article.new
  end
  
  def edit
    @article = Article.find(params[:id])
  end
  
  def create
    @article = Article.new(article_params)
  
    if @article.save
      redirect_to @article
    else
      render 'new'
    end
  end
  
  def update
    @article = Article.find(params[:id])
  
    if @article.update(article_params)
      redirect_to @article
    else
      render 'edit'
    end
  end
  
  def destroy
    @article = Article.find(params[:id])
    @article.destroy
  
    redirect_to articles_path
  end
  
  private
    def article_params
      #article_params =
      params.require(:article).permit(:title, :text, :attachment)
      #@article.update_attributes( article_params )
    end
  end
  </code></pre>
  
  <p>This is the error I have now locally and on heroku, next to many others before:</p>
  
  <p>uninitialized constant Paperclip::Storage::S3::AWS
  Extracted source (around line #26):</p>
  
  <pre><code>  @article = Article.new(article_params)
  
    if @article.save #line 26
      redirect_to @article
    else
      render 'new'
  </code></pre>
  
  <p><strong>Parameters:</strong></p>
  
  <pre><code>{"utf8"=&gt;"✓", "authenticity_token"=&gt;"snGgVwA5tqQTPHXwXW1Fx/lmLMS1bL+94jF68KQh031gpX2N78gOK45hCP8w71ObFo6moHQuJXxNnUW0bCUeVw==",
   "article"=&gt;
    {"title"=&gt;"test1",
     "text"=&gt;"",
     "attachment"=&gt;
      #&lt;ActionDispatch::Http::UploadedFile:0x007f46c00881e0
       @content_type="application/x-desktop",
       @headers="Content-Disposition: form-data; name=\"article[attachment]\"; filename=\"Antichamber.desktop\"\r\n" + "Content-Type: application/x-desktop\r\n",
       @original_filename="Antichamber.desktop",
       @tempfile=#&lt;File:/tmp/RackMultipart20170306-5350-esbhtd.desktop&gt;&gt;},
   "commit"=&gt;"Create Article"}
  </code></pre>
  
  <p>For convenience I add the URL to the broken Rails 5 app here:</p>
  
  <p><a href="https://infinite-taiga-25466.herokuapp.com/" rel="nofollow noreferrer">gmr-heroku</a></p>
  
  <p>Everything is working fine now!</p>
  
  <p>NB: You want me to pose different questions and not adding to the original question. Now you don't want duplicate answers.</p>