[Rails] Re: file_column do download from URL

Wiktor --- iktorn at gmail.com
Fri Aug 18 07:27:31 GMT 2006


Dion,

Thanks!

Here is how I fixed it:

In model:

  attr_accessor :url
  before_save :check_url

 private
  def check_url
    return if self.url.nil? or self.url.empty?
    file = open(self.url)
    if file.is_a? StringIO
      file.extend MyIOCompat
    else
      file.extend FileColumn::FileCompat
    end
    self.filename = file
  end

end

module MyIOCompat
  def original_filename; 'from_url'; end
end

There is no error checking so there may be some 500 errors but I use it 
only for admin purposes so it is ok.

-- 
Posted via http://www.ruby-forum.com/.


More information about the Rails mailing list