Ruby on rails 无法从facebook carrierwave上传图像
我目前有一个用户配置文件,允许用户上传一个图像文件,使用jQuery获取裁剪数据,然后将其发送到CarrierWave/RMagick进行裁剪/处理。它终于运作良好了 我现在遇到的问题是,如果用户注册了Facebook(oAuth),我想在默认情况下将他们的个人资料图像设置为他们的Facebook图像。我希望这是同一个字段(TalentProfile.profile_image),因为我希望用户能够通过自定义上载将其交换或删除(如果他们愿意) 以下是我目前拥有的流程:Ruby on rails 无法从facebook carrierwave上传图像,ruby-on-rails,ruby,carrierwave,Ruby On Rails,Ruby,Carrierwave,我目前有一个用户配置文件,允许用户上传一个图像文件,使用jQuery获取裁剪数据,然后将其发送到CarrierWave/RMagick进行裁剪/处理。它终于运作良好了 我现在遇到的问题是,如果用户注册了Facebook(oAuth),我想在默认情况下将他们的个人资料图像设置为他们的Facebook图像。我希望这是同一个字段(TalentProfile.profile_image),因为我希望用户能够通过自定义上载将其交换或删除(如果他们愿意) 以下是我目前拥有的流程: 用户注册facebook
- 用户注册facebook,用户已创建李>
- TalentProfile资源是在用户下创建的
- 在TalentProfile创建之后,我将添加profile_图像
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
class-TalentProfile
当self.set_facebook_image运行时,似乎@profile.profile_image不能这样设置,除非我删除mount_上传程序并验证行。尽管auth.info.image是我需要的URL,但它始终显示为nil。这让我相信,如果我更新它,CarrierWave不能像这样处理它;似乎需要提交表格
我怎样才能让这一切顺利进行?可能吗?谢谢你提供的任何信息 您应该使用此方法从远程url上载图像。您是说只需将
@profile.profile\u image=auth.info.image
行更改为@profile.remote\u profile\u image\u url=auth.info.image
?如果是这样的话,这似乎不起作用。我必须将该属性添加到我的模型中吗。我把那一行改成了@profile.update(remote\u profile\u image\u url:auth.info.image)
,它成功了。你是最棒的!非常感谢。