title: Can't get Paperclip to set my S3 URLs properly
body: <p>I'm using paperclip and aws-sdk gems in a Rails 4 app.</p>
  
  <p>I define the :path option in my paperclip.rb config, with no :url option:   </p>
  
  <pre><code>Paperclip::Attachment.default_options[:path] = ":class/:attachment/:id_partition/:style/:filename"
  </code></pre>
  
  <p>It saves my uploaded images like such:</p>
  
  <p><a href="http://s3.amazonaws.com/mybucket-development/profiles/avatars/000/000/026/original/image_file_name.png?1420575189" rel="noreferrer">http://s3.amazonaws.com/mybucket-development/profiles/avatars/000/000/026/original/image_file_name.png?1420575189</a></p>
  
  <p>All fine, it gets saved to S3. However it refuses to let me read the images for display, e.g. =profile.avatar.url(:medium). When I go to that URL in the browser it tells me to re-format it with the bucket name as a domain. Like:</p>
  
  <p><a href="http://mybucket-development.s3.amazonaws.com/profiles/avatars/000/000/026/original/image_file_name.png?1420575189" rel="noreferrer">http://mybucket-development.s3.amazonaws.com/profiles/avatars/000/000/026/original/image_file_name.png?1420575189</a></p>
  
  <p>OK, not a problem either. I go to that URL, I can view my image. So now I need to figure out how to get Paperclip to format the URLs like this automatically. I read in the Paperclip docs that you just have to set </p>
  
  <pre><code>Paperclip::Attachment.default_options[:url] = ":s3_domain_url"
  </code></pre>
  
  <p>And that I also have to set the :path parameter or I will just get a Paperclip::Errors::InfiniteInterpolationError.</p>
  
  <p>So I set my config file with both combined:</p>
  
  <pre><code>Paperclip::Attachment.default_options[:path] = ":class/:attachment/:id_partition/:style/:filename"
  Paperclip::Attachment.default_options[:url] = ":s3_domain_url"
  </code></pre>
  
  <p>Not working... I try scrapping the paperclip.rb and putting it in config/environments/* But no matter what I do, it still saves the URLs without the domain with the bucket name in the path. </p>
  
  <p>So two questions:</p>
  
  <p>1) How can I get Paperclip to automatically format the saved URLs in domain style?</p>
  
  <p>2) Or even better, how can I get S3 to accept the non-domain style URLs, the one that Paperclip is currently generating?</p>
  
  <p>EDIT</p>
  
  <p>So, if I add in the s3_host_name option then it saves the URLs domain style. So I have to have all 3 of:</p>
  
  <pre><code>Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
  Paperclip::Attachment.default_options[:path] = ":class/:attachment/:id_partition/:style/:filename"
  Paperclip::Attachment.default_options[:s3_host_name] = 's3-us-west-2.amazonaws.com'
  </code></pre>
  
  <p>And it will save my URLs on the model like so:</p>
  
  <p><a href="http://mybucket-development.s3-us-west-2.amazonaws.com/profiles/avatars/000/000/026/original/image_file_name.png%3F1420580224" rel="noreferrer">http://mybucket-development.s3-us-west-2.amazonaws.com/profiles/avatars/000/000/026/original/image_file_name.png%3F1420580224</a></p>
  
  <p>But now I see that I have a %3F encoding ("?") in the URL which messes it up. </p>