def self.current_transaction_batch_id
@current_transaction_batch_id ||= SecureRandom.hex
@current_transaction_batch_id
end
Hi, I have following method that is supposed to generate and return a batch id that I need to be unique for every request. But, the issue is that this method is returning the same value through multiple request which means the variable @current_transaction_batch_id is persisting through requests.
Thanks for help in advance
||=with=? Now assigning a new value to a variable only works when it's empty. Therefore, the value may be the same all the time.@current_transaction_batch_idwith a new random hex. But, I need a unique Hex throughout the lifespan of my request to remain the same.request.request_idmethod that has a unique uuid generated for a given request, which can be used instead of generating hex. Do you absolutely have to useSecureRandom.hex?@variable in a class method it is a "class instance variable" and since classes are not reloaded between requests it stays the same.