ruby on rails - How to make sure images uploaded with paperclip have unique names? -


i using paperclip save images. have created image model save them public director

class image < activerecord::base   has_attached_file :file,                     :url => "assets/projects_description_images/:style/:basename.:extension",                     :path => ":rails_root/public/assets/projects_description_images/:style/:basename.:extension"     validates_attachment :file,                        :presence => true,                        content_type: {content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif"]},                        :size => {:in => 0..50.megabytes} end 

however if add make image name "main.jpg" , create name "main.jpg" when displaying 1 created first shows second one. have no way of knowing exact name used can there duplicates. great if have file name saved like

main_(unique_string).jpg

any clue how this?

the answer provided andrey turkin ( trevorturk.com/2009/03/22/randomize-filename-in-paperclip)solved problem. 1 thing note rails 4.2 had change activesupport::securerandom.hex(16) just

securerandom.hex(16) 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -