Created
July 16, 2012 08:48
-
-
Save sunny0425/3121600 to your computer and use it in GitHub Desktop.
get image from link(use paperclip)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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