views:

49

answers:

2

please suggest me a way save image from url by paperclip. thanks

A: 

First download the image with the curb gem to a TempFile and then simply assign the tempfile object and save your model.

Ariejan
+1  A: 

Here is a simple way:

require "open-uri"

class User < ActiveRecord::Base
  has_attached_file :picture

  def picture_from_url(url)
    self.picture = open(url)
  end
end

Then simply :

user.picture_from_url "http://www.google.com/images/logos/ps_logo2.png"
slainer68
thank you. it helpful for me.
Nam Khanh