我有两个模型,每个模型都有自己的 Carrierwave 上传器:
class User < ActiveRecord::Base
mount_uploader :avatar, AvatarUploader
end
和:
class Bookshelf < ActiveRecord::Base
mount_uploader :image, ImageUploader
end
我希望用户的头像是他上传的最新书架图像。我尝试这样实现:
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
不幸的是,这对头像完全没有影响。我还能如何实现这一目标?