Given you use Rails 5.2 Active Storage for file uploads

# app/models/account.rb
class Account < ActiveRecord::Base
  has_one_attached :avatar
end

# rails console
a = Account.create
a.avatar.attach(io: File.open('/tmp/dog.jpg'), filename: 'dog.jpg')
a.save

by default the url for active storage is set to example.com

# rails console

app.url_for(a.avatar)
# => "http://www.example.com/rails/active_storage/blobs/xxxxxxxxxxxxxxxxxxxxxxxxxx/dog.jpg" 

app.rails_blob_url(a.avatar)
# => "http://www.example.com/rails/active_storage/blobs/xxxxxxxxxxxxxxxxxxxxxxxxxx/dog.jpg" 

To change the host name:

# config/environments/developent.rb
Rails.application.routes.default_url_options[:host] = 'localhost:3000'

Note: if you need to change http to https change Rails.application.routes.default_url_options[:protocol] = 'https'

# rails console

app.url_for(a.avatar)
# => "http://localhost:3000/rails/active_storage/blobs/xxxxxxxxxxxxxxxxxxxxxxxxxx/dog.jpg" 

app.rails_blob_url(a.avatar)
# => "http://localhost:3000/rails/active_storage/blobs/xxxxxxxxxxxxxxxxxxxxxxxxxx/dog.jpg" 

BTW there is also rails_blob_path helper to fetch path without host

source:

discussion