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

Possible to reorder multiple attached files without reuploading? #2337

Closed
veborich opened this issue Sep 17, 2018 · 2 comments
Closed

Possible to reorder multiple attached files without reuploading? #2337

veborich opened this issue Sep 17, 2018 · 2 comments

Comments

@veborich
Copy link

Hi say I want a user to be able to upload multiple avatars, but I want them to be able to set their default avatar. Since the only record I can see of avatars in the db is the array of filenames, I figured the best way to set the "default" is have it be at the zero index.

Using this guide on modifying instead of replacing uploads.

The guide shows example code of making an array copy, changing the array, then reassign it to the model's uploads. I have done this as below:

    index = params[:index].to_i
    all_avatars = @user.avatars
    old_default_avatar = all_avatars[0]
    new_default_avatar = all_avatars[index]
    all_avatars[0] = new_default_avatar
    all_avatars[index] = old_default_avatar
    @user.avatars = all_avatars

And it works! But it works by reuploading ALL the avatars all over again. This makes the action itself pretty slow, and is going to be much worse for larger images that aren't avatars. Am I missing something obvious? Is there perhaps a way to add a validation that if the upload hasn't changed position, don't reupload?

@BryanH
Copy link

BryanH commented Jan 24, 2019

Ask support questions on StackOverflow

@mshibuya
Copy link
Member

Closed by #2401.

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

3 participants