AnApprentice
AnApprentice

Reputation: 111060

rails 3 - paperclip

With paperclip, how can you get paperclip to use full urls like http://mysite.com/image/asdasd.png

versus /image/asdad.png

thanks

Upvotes: 1

Views: 2921

Answers (3)

Nimesh Nikum
Nimesh Nikum

Reputation: 1839

If you are uploading files to amazon S3 then

s3.url
gives the full image path. But in case of local file storage, you can set :url option also

Upvotes: 0

yfeldblum
yfeldblum

Reputation: 65445

Once you configure the :url interpolation string to your satisfaction, you can link to attachments with the full URL using something like:

def attachment_path(attachment)
  attachment.url
end

def attachment_url(attachment)
  "#{root_url}#{attachment.url.gsub(/^\//, '')}"
end

Upvotes: 2

Ben Hughes
Ben Hughes

Reputation: 14195

Assuming you want the behavior to work like the _url helpers on the controller/view level, its a little complicated as paperclip functions without the benefit of knowing the host from the request. An easy way to get around this is to define the constant HOST in the config/environments/ENV.rb and then passing the url parameter to has_attachment like

:url => "http://#{HOST}/:path"

or whatever your url rules are.

You can also side step this issue by using S3, which is kind of a life saver

Upvotes: 1

Related Questions