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/