Skip to content

Instantly share code, notes, and snippets.

@sunny0425
Created July 16, 2012 08:48
Show Gist options
  • Save sunny0425/3121600 to your computer and use it in GitHub Desktop.
Save sunny0425/3121600 to your computer and use it in GitHub Desktop.
get image from link(use paperclip)
require "open-uri"
require 'tempfile'
def image_from_url(url)
ext = File.extname(url)
filename = File.basename(url, ext)
temp = Tempfile.new([filename, ext])
str = open(url).read
temp.write(str)
File.open(temp.path) do |f|
self.image = f
self.save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment