title: Can't retrieve file from S3 with Rails Active Storage
body: <p>I am trying to upload a photo to S3 using Rails Active Storage.</p>
  
  <p>I can attach a photo:</p>
  
  <p><code>user.photo.attach(io: File.open('spec/images/filename.png'), filename: 'filename.png')</code></p>
  
  <p>I can save the user and I can get the photo service url and see it in the browser, and in my bucket:</p>
  
  <p><code>user.photo.service_url</code></p>
  
  <p>However, if I restart my console and try to get the service url, I receive the following error:</p>
  
  <p><code>Module::DelegationError (service_url delegated to attachment, but attachment is nil)</code></p>
  
  <p>Here are my bucket settings:</p>
  
  <p>storage.yml:</p>
  
  <pre><code>amazon:
    service: S3
    access_key_id: &lt;%= Rails.application.credentials.dig(:aws, :access_key_id) %&gt;
    secret_access_key: &lt;%= Rails.application.credentials.dig(:aws, :secret_access_key) %&gt;
    region: us-east-2
    bucket: &lt;%= Rails.application.credentials.dig(:aws, :bucket) %&gt;
  </code></pre>
  
  <p>application.rb:</p>
  
  <p><code>config.active_storage.service = :amazon</code></p>
  
  <p>user.rb:</p>
  
  <p><code>has_one_attached :photo</code></p>
  
  <p>I am also having trouble using <code>public: true</code> in the storage.yml file.</p>
  
  <p>I receive the following error if I try to set the config:</p>
  
  <pre><code>ArgumentError (Cannot load `Rails.config.active_storage.service`:)
  invalid configuration option `:public'
  </code></pre>
  
  <pre><code>amazon:
    service: S3
    access_key_id: &lt;%= Rails.application.credentials.dig(:aws, :access_key_id) %&gt;
    secret_access_key: &lt;%= Rails.application.credentials.dig(:aws, :secret_access_key) %&gt;
    region: us-east-2
    bucket: &lt;%= Rails.application.credentials.dig(:aws, :bucket) %&gt;
    public: true
  </code></pre>