This is my code to obtain an UUID:
def manage_id
self.id = UUIDTools::UUID.random_create().to_s.upcase if self.id.blank?
end
This works perfectly for the primary key of my object.
My problem is I want to name an uploaded file with an UUID… and I obtain the same UUID for different uploads. For example I will have an UUID and 2 minutes later with another object I will have the same UUID !
This is the class code to name my image:
:filename => "#{UUIDTools::UUID.random_create().to_s.upcase}.jpg" }
I don’t understand what can be the problem when generating the UUID…
I have not the problem in development !!!
EDIT 1: the problem is not with UUID itself, it’s the same with a timestamp… (and only in production)
EDIT 2: I found the problem. The setting:
config.cache_classes = true
is the problem in production mode. It is certainly keeping the UUID somewhere in memory.
I think I can’t switch to false in production mode (for performance), so what is the best way to deactivate the cache for this plugin name feature ?
EDIT 3: I add the full code of my model
class Product < ActiveRecord::Base
file_column :image, {:magick => { :versions => { "tiny" => "70x70", "small" => "160x240", "high" => "640x960" }}, :store_dir => "public/upload/wine/image", :web_root => "upload/", :filename => "#{UUIDTools::UUID.timestamp_create().to_s.upcase}.jpg" }
end
So, as I said the UUID generated is cached in production. I don’t know how to force this model or maybe the plugin file_column to not be cached ?
The reason that it doesn’t work for you because you always use pre-initialized option.
But you can try to change something to improve it. For example you can use lambda expression for calcaulationg filename … Try something like next
and change this
to