Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails omniauth facebook用户档案成为管理员';照片_Ruby On Rails_Facebook Graph Api_Devise_Omniauth_Omniauth Facebook - Fatal编程技术网

Ruby on rails omniauth facebook用户档案成为管理员';照片

Ruby on rails omniauth facebook用户档案成为管理员';照片,ruby-on-rails,facebook-graph-api,devise,omniauth,omniauth-facebook,Ruby On Rails,Facebook Graph Api,Devise,Omniauth,Omniauth Facebook,我将omniauth facebook gem与gem集成到我的网站中,并添加了一些facebook好友作为我应用程序的测试者,但每次有人登录使用facebook时,我的图片作为管理员会被持久化为他们的图片。奇怪的是,他们的名字和姓氏得到了正确的保留。该应用程序仍处于沙盒模式 在models/user.rb中,我得到了 def self.from_omniauth(auth) where(provider: auth.provider, uid: auth.uid).first_or_cre

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

在models/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
config.omniauth :facebook, "APP-ID", "APP-SECRET", :scope => "email, public_profile", :image_size => "normal", :secure_image_url => true
在initializers/designe.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
config.omniauth :facebook, "APP-ID", "APP-SECRET", :scope => "email, public_profile", :image_size => "normal", :secure_image_url => true
编辑1:
我正在使用dropbox应用程序托管图片。在应用程序中,我可以看到测试人员的图片被持久化为图片、图片(1)、图片(2)等等。当我打开rails控制台时,每个测试人员配置文件的头像文件名(因为我使用的是回形针gem)都是“图片”,因此所有人都得到相同的配置文件图片。是否有一种方法将图片保存为图片-“UID”,以便它们都获得不同的名称?

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

在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/