簡體   English   中英

使用Omniauth-Facebook Gem添加個人資料圖片的最簡單方法是什么?

[英]What is the simplest way to add an profile image with the Omniauth-Facebook Gem?

我正在使用帶有Rails的Omniauth Facebook Gem,需要為我的應用程序選擇每個用戶的個人資料。

是否像使用Gem從facebook檢索用戶名一樣簡單,還是需要將其上傳到Amazon S3服務器等?

我的用戶模型:

def self.from_omniauth(auth)
    where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
      user.provider = auth.provider
      user.uid = auth.uid
      user.name = auth.info.name
      user.oauth_token = auth.credentials.token
      user.oauth_expires_at = Time.at(auth.credentials.expires_at)
      user.save!
    end

找不到明確的答案。

更新:在我的展示頁面中,它只顯示網址:

<b>IMAGE:</b> <%= @user.image %>

謝謝

這很簡單。 而且您不需要在服務器上存儲圖像。 你可以簡單地從Facebook上獲取它。

我是這樣做的:
User模型中添加image字段:

rails generate migration addImageToUsers image:string

添加attr_accessible列表。

然后在上面的方法中,為圖片添加以下列表:

user.image = auth.info.image

這是facebook存儲用戶圖像的直接網址。

您可以inspect您的auth哈希來研究不同大小的用戶圖像。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM