Skip to content
New issue

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

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

Already on GitHub? # to your account

Bug: #update(remove_file: "0") always change model if 'file' is present #2323

Closed
Flauschbaellchen opened this issue Jun 27, 2018 · 1 comment
Labels

Comments

@Flauschbaellchen
Copy link

I came across this issue while using carrierwave and paper_trail on the same model as despite saving no changes, paper_trail added always a new revision displaying that file has been changed.
However, the value of file was the same so I dig a bit deeper to find what did gone wrong.
You do not need paper_trail to follow up.

A little bit of pseudo-code:

Setup model to use carrierwave:

class MyModel < ApplicationRecord
  mount_uploader :file, FileUploader, mount_on: :file
end

Create and update model but do not change anything:

m = MyModel.create()
m.update(remove_file: "0") # does nothing

Update model with no changes if file is present:

m = MyModel.create()
m.file = <SomeFile>
m.save

m.update(remove_file: "0") # saves the same value to `file` column again.

Even there are no changes, every hook is fired which listen on change-events for this column.
In my case this was paper_trail for tracking revisions.

Workaround: Delete param remove_file if it is "0" within controller prior to #update.

@Flauschbaellchen Flauschbaellchen changed the title Bug: #update(remove_file: "0") always change model if file is present Bug: #update(remove_file: "0") always change model if 'file' is present Jun 27, 2018
@jonian
Copy link

jonian commented Sep 11, 2018

I can confirm this. It occurs also with:

m = MyModel.create()
m.update(remove_file: "")

I tested this with a form check-box.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants