I’m creating an image uploader of sorts, and would like all of the
filenames of uploaded files to be completely random when saved. I am
fairly new to Ruby, Rails, and attachment_fu, and came up with the
following earliar:
def filename=(new_name)
new_name =
“#{Digest::SHA1.hexdigest(Time.now.to_s)}#{File.extname(new_name)}”
write_attribute :filename, sanitize_filename(new_name)
end
end
This works, creating filenames such as
‘4de12252220d679aa99b12be835ab56c7a5f7fc9.png’, but it doesn’t set the
thumbnail name correctly (i.e:
4de12252220d679aa99b12be835ab56c7a5f7fc9_thumb.png) - instead, it
saves it with the same filename
(4de12252220d679aa99b12be835ab56c7a5f7fc9.png).
Does anyone have any ideas on how I can achieve this?