0

In my application users can already upload photos from file, but I want to extend this to adding photos from web urls. I've been trying for some time but I just can't get it to work.

I'm using paperclip 3.1.4.

I have this code in my model file

require 'open-uri'
class User < ActiveRecord::Base
 # paperclip avatars on S3
 has_attached_file :avatar, {
                  :styles => { :medium => "200x200", :small => "100x100#", :thumb => "64x64#" },
                  :default_url => "/assets/profiles/avatar_default_200x200.png",
                  :path => "/avatars/:style/:id/:filename",
                  :url => "/avatars/:style/:id/:filename"
 }.merge(PAPERCLIP_STORAGE_OPTIONS)

def avatar_from_url(url)
  self.avatar = URI.parse(url)
end

I then use this code to test it

- user.avatar_from_url "http://www.wellcomeimageawards.org/stellent/groups/wia/@msh_publishing_group/documents/image/WTVM055068.jpg"
= image_tag user.avatar.url

But in the rendered html the image is blank and the source for the image is given as

http://s3.amazonaws.com/eightythousand.org/avatars/original//WTVM055068.jpg?1362144498

What am I doing wrong?

4

0 回答 0