0

我将omniauth-facebook gem与宝石集成到我的网站中,并添加了一些Facebook好友作为我的应用程序的测试人员,但每次有人使用Facebook登录我的照片作为管理员时,作为他们的照片。奇怪的是,他们的名字和姓氏得到正确保存。该应用程序仍处于沙盒模式。omniauth-facebook用户资料成为管理员的图片

在模型

/user.rb我有

def self.from_omniauth(auth) 
    where(provider: auth.provider, uid: auth.uid).first_or_create do |user| 
    user.email = auth.info.email 
    user.password = Devise.friendly_token[0,20] 
    user.firstname = auth.info.first_name 
    user.lastname = auth.info.last_name 
    user.avatar = auth.info.image 
    end 
end 

def self.new_with_session(params, session) 
    super.tap do |user| 
    if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"] 
     user.email = data["email"] if user.email.blank? 
    end 
    end 
end 

和初始化/ devise.rb我有

config.omniauth :facebook, "APP-ID", "APP-SECRET", :scope => "email, public_profile", :image_size => "normal", :secure_image_url => true 

编辑1: 我主持使用Dropbox应用程序的图片。在应用程序中,我可以看到测试图片被保存为图片,图片(1),图片(2)等等。当我打开导轨控制台时,avatar_file_name(因为我使用回形针宝石)对每个测试者配置文件都是“图片”,因此所有人都可以获得相同的配置文件图片。有没有一种方法将图片保存为图片 - “UID”,以便它们都可以获得不同的名称?

回答

0

似乎可以通过使用路径选项来解决问题的解决方案。

in models/user.rb并添加了指纹以进行更多的消毒。

fingerprint = Time.now 

has_attached_file :avatar, :styles => { :medium => "300x300>", :pin => "30x30>" }, :default_url => "/images/missing.png", :storage => :dropbox, :dropbox_credentials => Rails.root.join("config/dropbox.yml"), :path => ":style/#{fingerprint}_:id_:filename" 
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/