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

Files get overwritten #2291

Closed
hacktorious opened this issue Mar 8, 2018 · 2 comments
Closed

Files get overwritten #2291

hacktorious opened this issue Mar 8, 2018 · 2 comments

Comments

@hacktorious
Copy link

hacktorious commented Mar 8, 2018

Hello,

I'm attempting to use Carrierwave in rails 5 and am not having much luck using array file uploads on updates.

I have a form with several fields and a file select button. I can create and save the initial object without any trouble. The problem comes in when I try to do an update with something like @my_object.update_attributes(my_object_params).

If I try to add additional files when updating the form my initial files are overwritten with the new files. Even if I do something like this beforehand:

original_images = @my_object.find(params[:id]).images new_images = params[:my_object][:images] @my_object.images = original_images + new_images

Doing a "puts" here shows the newly added files, as well as the original files are in @my_object.

Calling @my_object.save only allows the files to be saved and won't update the form fields. So using this isn't really a viable option.
If I call @my_object.update_attributes(my_object_params), or @my_object.update(my_object_params). The form fields are updated, but the files in the array are completely rewritten with only the newly updated files. This seems bizarre to me since I updated the file array in @my_object with both the original and new files.

Apparently there aren't any callback methods to prevent this behavior as stated in the README file. I just get an error when trying to use a callback stating the callback method has not been defined.

ie:
`

  • after_commit :remove_previously_stored_my_object, on: :update . (Singular Version obviously won't exist)
    skip_callback :commit, :after, :remove_previously_stored_my_object

  • after_commit :remove_previously_stored_my_objects, on: :update (I would expect a plural version to be available)
    skip_callback :commit, :after, :remove_previously_stored_my_objects
    `

I've been working on this issue for a week and unfortunately I cannot find a solution. I will have to pull out carrierwave and do everything manually if I cannot resolve this soon. This would obviously not be ideal.

Please help! Thanks.

@hacktorious
Copy link
Author

I'm pretty sure there is a bug in the CarrierWave code causing this issue since the config settings, which are supposed to prevent this behavior don't do anything.
config.remove_previously_stored_files_after_update = false

@mshibuya
Copy link
Member

Closed by #2401.

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

2 participants