title: URI::InvalidURIError (bad URI(is not URI?): nil) Active Storage service_url
body: <p><strong>Config Info</strong></p>
  <pre><code>rails version 6.0
  ruby version 2.7.0
  gem 'image_processing', '~&gt; 1.2'
  </code></pre>
  <p><strong>storage.yml</strong></p>
  <pre><code>local:
    service: Disk
    root: &lt;%= Rails.root.join(&quot;storage&quot;) %&gt;
  </code></pre>
  <p><strong>development.rb</strong></p>
  <pre><code>config.active_storage.service = :local
  Rails.application.routes.default_url_options[:host] = 'localhost:3000'
  config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
  </code></pre>
  <p><strong>This exception is coming only when I'm using <code>service= :local</code>.</strong> With AWS S3 config, on using <code>:amazon</code> it works fine.</p>
  <p><strong>user.rb</strong> model</p>
  <pre><code>  has_one_attached :avatar
    
    #throwing exception
    def avatar_urls
      {
        original: avatar.service_url
      } if avatar.attachment
    end
  </code></pre>
  <p>While accessing <code>avatar_urls</code> the exception(<code>URI::InvalidURIError (bad URI(is not URI?): nil) </code>) is thrown. However, as If I change my <code>avatars_url</code> method to following, it works fine.</p>
  <pre><code>  #working method
    def avatar_urls
      {
        thumbnail: url_for(avatar.variant(resize: &quot;100x100&quot;).processed)
      } if avatar.attachment
    end
  </code></pre>
  <p>Here is the trace:</p>
  <pre><code>Disk Storage (5056.7ms) Generated URL for file at key: variants/i5w1ie6ro07mib4qcdn30lmik6wn/2a7fa5dad6ac227a16e961cbd12ca6f35f1d7947f56a97754d5e22c1a0fd3372 ()
  cb_app_container | Completed 500 Internal Server Error in 9523ms (ActiveRecord: 580.9ms | Allocations: 1185509)
  cb_app_container | URI::InvalidURIError (bad URI(is not URI?): nil):
  cb_app_container | app/models/user.rb:53:in `avatar_urls'
  cb_app_container | app/models/user.rb:27:in `user_json'
  cb_app_container | app/controllers/api/v1/users_controller.rb:13:in `update'
  cb_app_container | [ActiveJob] [ActiveStorage::AnalyzeJob] [33448db4-cf54-4677-906c-06b59f1579ee]    (61.6ms)  BEGIN
  cb_app_container | [ActiveJob] [ActiveStorage::AnalyzeJob] [33448db4-cf54-4677-906c-06b59f1579ee]   ActiveStorage::Blob Update (10.3ms)  UPDATE &quot;active_storage_blobs&quot; SET &quot;metadata&quot; = $1 WHERE &quot;active_storage_blobs&quot;.&quot;id&quot; = $2  [[&quot;metadata&quot;, &quot;{\&quot;identified\&quot;:true,\&quot;width\&quot;:1952,\&quot;height\&quot;:3264,\&quot;analyzed\&quot;:true}&quot;], [&quot;id&quot;, 45]]
  cb_app_container | [ActiveJob] [ActiveStorage::AnalyzeJob] [33448db4-cf54-4677-906c-06b59f1579ee]    (19.6ms)  COMMIT
  cb_app_container | [ActiveJob] [ActiveStorage::AnalyzeJob] [33448db4-cf54-4677-906c-06b59f1579ee] Performed ActiveStorage::AnalyzeJob (Job ID: 33448db4-cf54-4677-906c-06b59f1579ee) from Async(default) in 6916.06ms
  </code></pre>