I have two models, each with their own Carrierwave uploaders:
class User < ActiveRecord::Base
mount_uploader :avatar, AvatarUploader
end
and:
class Bookshelf < ActiveRecord::Base
mount_uploader :image, ImageUploader
end
I want the user's avatar to be the latest bookshelf image he's uploaded. I try to achieve this like so:
class BookcasesController < ApplicationController
def create
@bookcase = current_user.bookcases.build(params[:bookcase])
if @bookcase.save
current_user.avatar = @bookcase.image
current_user.avatar.recreate_versions!
end
end
end
Unfortunately, this has no effect on the avatar at all. How else might I achieve this?
current_user.avatar = @bookcase.image
current_user.avatar.recreate_versions!
Doesn't actually save --- you can either:
current_user.avatar.save
or as you put:
current_user.update_attribute(:avatar, @bookcase.image)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With