Skip to content

Instantly share code, notes, and snippets.

@madhums
Created March 28, 2011 08:17
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 madhums/890149 to your computer and use it in GitHub Desktop.
Save madhums/890149 to your computer and use it in GitHub Desktop.
Upload images to paperclip with remote uri's
require 'open-uri'
#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
<% 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