Q:

How to change S3 bucket URL to bucket first then url second

I am creating a rails API app using Paperclip and aws-sdk gems. 
The app saves the URL as a string. The url saved is the following.
http://s3.amazonaws.com/S3_BUCKET_/profiles/avatars/000/000/001/original/avatar.png?1457514823
I cant open the above image. Its because the url for it when taken from s3 is the following
http://S3_BUCKET_/s3.amazonaws.com//profiles/avatars/000/000/001/original/avatar.png?1457514823
See how the bucket is first? But the url saved in the database has the bucket second? How do i change the saved URL to have the bucket first?
config/initializers/paperclip.rb

Paperclip::Attachment.default_options.update(
  default_url: "https://#{Rails.application.secrets.bucket}.s3-ap-southeast-2.amazonaws.com/" \
               "/profiles/avatars/default/missing.jpg")

config/aws.yml

development: &defaults
  access_key_id:     s3_access_key
  secret_access_key: s3 secret key
  s3_region:         ap-southeast-2

test:
  secret_access_key: s3 secret key

staging:
  <<: *defaults
  access_key_id:     s3_access_key
  secret_access_key: <%= ENV["SECRET_KEY_BASE"] %>

production:
  <<: *defaults
  access_key_id:     s3_access_key
  secret_access_key: <%= ENV["SECRET_KEY_BASE"] %>

profile.rb it has the attachment saved

require "base64"
class Profile < ActiveRecord::Base
  belongs_to :user
  validates :user, presence: true

  has_attached_file :avatar, styles: { thumb: "100x100>" }

  validates_attachment_content_type :avatar, content_type: /image/i

  def avatar_url
    avatar && avatar.url
  end

  def avatar_base64=(image_base64)
    file = Paperclip.io_adapters.for(image_base64)
    file.original_filename = file.content_type.sub("image/", "avatar.")
    self.avatar = file
  end

A:

You can add a default url in config/initializers/paperclip.rb like this:
Paperclip::Attachment.default_options[:url] = ':s3_domain_url'

Or you can configure directly in your environment configuration, i.e. config/environments/production.rb:
config.paperclip_defaults = {
    storage: :s3,
    url: ':s3_domain_url',
    ...
}

It's important to note that :s3_domain_url is a string, not a symbol.

