Reputation: 154
I am running a background task, need to convert image to jpeg and store it. I am using CarrierWave uploader. Here's the code
task reformat_user: :environment do
User.all.each do |u|
u.avatar.manipulate! do |av|
av.format('jpg')
av
end
end
However I could find no option to replace user avatar with a new one
Upvotes: 0
Views: 860
Reputation: 3790
If you need to replace user avatar with new, you just need to assign a new file to avatar
u.avatar = params[:file] # params[:file] contains the file uploaded by user from UI.
u.save!
OR this way
File.open('path_of_new_avatar') do |f|
u.avatar = f
end
u.save!
I hope I understood your question correctly.
Upvotes: 2