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

Fix #dup with custom serialisation #2771

Conversation

nassim-platogo
Copy link
Contributor

@nassim-platogo nassim-platogo commented Jan 7, 2025

While write_uploader is aliased by default to write_attribute, it may be overridden in the model (see example below).

class SomeModel < ActiveRecord::Base
  store :settings, accessors: [:logo] # virtual column logo

  mount_uploader :logo, LogoUploader

  def write_uploader(column, identifier)
    settings[column.to_sym] = identifier
  end

  def read_uploader(column)
    settings[column.to_sym]
  end
end

However duplicating such a model fails with the following error.

[1] pry(main)> SomeModel.new.dup
ActiveModel::MissingAttributeError: can't write unknown attribute `logo

This change ensures that on duplication, the override write_uploader method is called when clearing the attribute.

While `write_uploader` is aliased to `write_attribute` by default,
it may be overridden in the model. This change ensures that the
override method is called when clearing the attribute.
@nassim-platogo nassim-platogo force-pushed the bugfix/use-write-uploader-on-dup branch from 85a7973 to 7cda4e4 Compare January 7, 2025 13:26
@nassim-platogo nassim-platogo marked this pull request as ready for review January 7, 2025 13:33
@mshibuya mshibuya merged commit 97bd98b into carrierwaveuploader:master Jan 11, 2025
15 checks passed
@mshibuya
Copy link
Member

You're right. Thanks!

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

Successfully merging this pull request may close these issues.

2 participants