Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mounted uploader column is populated on create, even when no file is present, when using filename override #2284

Closed
lpradovera opened this issue Feb 26, 2018 · 1 comment

Comments

@lpradovera
Copy link

The following is a console snippet from our application (newlines added for readability):

   (0.3ms)  BEGIN
  SQL (1.9ms)  INSERT INTO "customers" ("customer_number", "created_at", "updated_at", 
"recording_file") VALUES ($1, $2, $3, $4) RETURNING "id"  [["customer_number", "f123456"], 
["created_at", "2018-02-26 20:01:37.848502"], ["updated_at", "2018-02-26 20:01:37.848502"], 
["recording_file", "f123456.mp3"]]
   (0.6ms)  COMMIT

Code is a very simple uploader, with

def filename
    "#{model.customer_number}.mp3"
end

As you can see, the recording_file column, corresponding to a mounted uploader, is being set on create even if there is no attachment. When using Fog and S3, it results in recording_file_url erroneously returning a path.

We are on Rails 5.1, Carrierwave 1.2.1.

@raulccabreu
Copy link

raulccabreu commented Feb 27, 2020

I had this problem too, try this with your override.

def filename
    return @filename if file.nil?
    "#{model.customer_number}.mp3"
end

@mshibuya mshibuya added this to the Release v3.0.0 milestone Jan 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants