Posts Tagged file upload

Uploading file with URL in paperclip

You must have handled paperclip and must have used similar kind of code

has_attached_file :avatar

Now say that you want to upload it from  a url, well thats simple, just create a virtual attribute as shown

  def picture_from_url=url
    self.avatar = open(url)

At the top of the file require this one

require "open-uri"

For reading the file from any where from the internet and put it into the object.

Now in console or  any where in code you can write the following code

p =

p.picture_from_url = ""

And Briyani image will be set to the persons avatar.


, , ,

Leave a comment

When Paperclip uploads are not served in production

You need to do  a file upload and you follow paperclip ( ) docs and  upload. All works well in development mode, but in production somehow the uploaded images does not get served and you are wondering why. To rectify this, search for this file <app_path>/config/production.rb and in it search for this statement

config.serve_static_assets = false

Change it to the following

config.serve_static_assets = true

Thats it , the issue must be fixed.

, , , , ,