【发布时间】:2017-08-18 16:57:05
【问题描述】:
我目前有一个用户配置文件,允许用户上传图像文件,使用 jQuery 获取裁剪数据,然后将其发送到 CarrierWave/RMagick 进行裁剪/处理。它终于运作良好。
我现在遇到的问题是,如果用户使用 Facebook (oAuth) 注册,我想将他们的个人资料图像默认设置为他们的 Facebook 图像。我希望这是同一个字段 (TalentProfile.profile_image),因为我希望用户能够将其替换为自定义上传或根据需要将其删除。
这是我目前的流程:
- 用户使用 facebook 注册,用户已创建。
- TalentProfile 资源在用户下创建
- 我去创建 TalentProfile 之后添加 profile_image。
这是我的 Talent_profile.rb 模型:
class TalentProfile < ApplicationRecord
belongs_to :user
mount_uploader :profile_image, ProfileImageUploader
validates :profile_image, file_size: { less_than: 5.megabytes }
def crop_profile_image
if crop_x.present?
profile_image.recreate_versions!
end
end
def self.set_facebook_image(profileId, auth)
@profile = TalentProfile.find(profileId)
@profile.profile_image = auth.info.image
byebug
end
end
运行 self.set_facebook_image 时,似乎无法像这样设置 @profile.profile_image,除非我删除 mount_uploader 并验证行。它总是以 nil 的形式出现,即使 auth.info.image 是我需要的 URL。这让我相信,如果我更新它,CarrierWave 无法像这样处理它;好像需要提交表单。
我怎样才能完成这项工作?是否可以?感谢您提供任何信息!
【问题讨论】:
标签: ruby-on-rails ruby carrierwave