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

regenerating versions doesn't work #71

Closed
kschaper opened this issue Jul 29, 2016 · 3 comments
Closed

regenerating versions doesn't work #71

kschaper opened this issue Jul 29, 2016 · 3 comments

Comments

@kschaper
Copy link

Hi Janko,

first of all thanks a lot for the great Shrine, I really like it.

I tried to follow the guide on Reprocessing Versions. It doesn't work because Shrine::Plugins::Activerecord::AttacherMethods.swap must not be private. This is in my Rake task:

Photo.all.each do |photo|
  attacher, attachment = photo.image_attacher, photo.image
  if attacher.stored?
    file_500 = resize_to_limit(attachment[:large].download, 500, 500)
    medium = attacher.store!(file_500, version: :medium)
    attacher.swap(attachment.merge(medium: medium))
  end
end

Sorry I can't provide a pull request right now.

Cheers
Kai

@janko
Copy link
Member

janko commented Jul 30, 2016

Thanks for reporting, I will fix this shortly.

In the meanwhile, you can use attacher.send(:swap, ...). Also, I don't know how many Photo records you have, but it's generally better to use Photo.find_each, otherwise all Photo records are loaded in memory.

@janko janko closed this as completed in e7af631 Jul 30, 2016
@janko
Copy link
Member

janko commented Jul 30, 2016

I named the commit message wrong, it actually does make Attacher#swap public 😄

@kschaper
Copy link
Author

Thank you for fixing this so quickly.

At the moment I'm playing around with just a couple of files. So Photo.all.each work fine for now. But I'm aware that find_each is a better way to deal with thousands of records.

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