You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
The text was updated successfully, but these errors were encountered:
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
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.
The text was updated successfully, but these errors were encountered: