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

attachment_cache is not working with nested attributes #2206

Closed
mdesantis opened this issue Jul 21, 2017 · 3 comments
Closed

attachment_cache is not working with nested attributes #2206

mdesantis opened this issue Jul 21, 2017 · 3 comments

Comments

@mdesantis
Copy link

I'm facing this issue on Rails 5.1.2 and Carrierwave 1.1.0, even using rails console:

irb(main):013:0> ci = Cover::Item.find 18
irb(main):014:0> new_attributes = {"id"=>"69", "attachment_cache"=>"1500657554-16427-0005-2355/KITTY.jpg"}
irb(main):015:0> ci.update teaser_image_horizontal_attributes: new_attributes
=> true

But the image file is not updated,
but if I do:

ci.teaser_image_horizontal.update attachment_cache: "1500657554-16427-0005-2355/KITTY.jpg"

it gets updated

@mdesantis
Copy link
Author

I found that after_validation callback is reached in both cases, but before_save is reached in not nested attributes case only

@mdesantis
Copy link
Author

mdesantis commented Jul 21, 2017

It seems that if you pass some other attribute to be updated, like for example updated_at: Time.now, works

@mdesantis
Copy link
Author

mdesantis commented Jul 28, 2017

Workaround:

  # inside the model class with `mount_uploader`
  before_validation do
    attachment_will_change! if attachment_cache.present?
  end

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