Posts Tagged file upload
You must have handled paperclip and must have used similar kind of code
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) end
At the top of the file require this one
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 = Person.new p.picture_from_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/Hyderabadi_Chicken_Biryani.jpg/250px-Hyderabadi_Chicken_Biryani.jpg" p.save
And Briyani image will be set to the persons avatar.
You need to do a file upload and you follow paperclip ( https://github.com/thoughtbot/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.