Skip to content

Instantly share code, notes, and snippets.

@zealot128
Created July 22, 2012 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zealot128/3160179 to your computer and use it in GitHub Desktop.
Save zealot128/3160179 to your computer and use it in GitHub Desktop.
Download an URL with open-uri to paperclip
# encoding: utf-8
def download_url(url)
url.gsub!(" ","%20")
# TODO better escaping of stuff like umlauts
# url.gsub!("ö","%C3%B6")
logo_path = url.split("/").last
io = open(url)
io.define_singleton_method(:original_filename) do
logo_path
end
io
end
# using is easy:
# model.photo = download_url('http://...jpg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment