Created
March 28, 2011 08:17
-
-
Save madhums/890149 to your computer and use it in GitHub Desktop.
Upload images to paperclip with remote uri's
This file contains 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' |
This file contains 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
#flickr image is your virtual attribute, where as image is your paperclip configured field | |
def flickr_image=(url) | |
unless url.strip.blank? | |
io = open(URI.parse(url)) | |
def io.original_filename; base_uri.path.split('/').last; end | |
self.image = io.original_filename.blank? ? nil : io | |
end | |
end | |
def flickr_image | |
end |
This file contains 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
<% form_for @model do |f| %> | |
<%= f.text_field :flickr_image %> | |
<% end %> | |
<!-- enter the url containing image in the text field --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment