Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7854309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:01:16+00:00 2026-06-02T20:01:16+00:00

This is my code to obtain an UUID: def manage_id self.id = UUIDTools::UUID.random_create().to_s.upcase if

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:01:19+00:00Added an answer on June 2, 2026 at 8:01 pm

    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

    file_column :image, {:magick => 
                                { :versions => 
                                    { "tiny" => "70x70", "small" => "160x240", "high" => "640x960" }
                                 },
                                 :store_dir => "public/upload/wine/image", 
                                 :web_root => "upload/", 
                                 :filename => lambda { "#{UUIDTools::UUID.timestamp_create().to_s.upcase}.jpg"} }
    

    and change this

    Assign filename to temp image path. Update code @class TempUploadedFile store_upload method line number 219

    @filename = options[:filename] || FileColumn::sanitize_filename(file.original_filename)
    

    to

    options_file_name = options[:filename].respond_to?(:call) ? options[:filename].call : options[:filename]
    
    
       @filename = options_file_name || FileColumn::sanitize_filename(file.original_filename)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code: (self is a subclass of NSView) rotate = [CABasicAnimation animationWithKeyPath:@transform.rotation.z]; rotate.duration =
This code works: monkey.h @interface monkey : NSObject { NSNumber *monkeyRanch; } @property (nonatomic,
I want to obtain last links from specific user account. I use this code:
This code works fine: Query query = parser.Parse(expression); IFullTextSession session = Search.CreateFullTextSession(this.Session); IFullTextQuery fullTextQuery
I use this code snippet to obtain a file as an input stream. The
I have this code to obtain a code country, but I want to see
When I run rake db:migrate for this code http://github.com/jonastryggvi/facebook-rails , I obtain : can't
I have this code to get the local date/time. It works but it seems
This Code: Something = new Guid() is returning: 00000000-0000-0000-0000-000000000000 all the time and I
This code gives me an empty result. I expect it to print out the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.