I'm working with the Omniauth Facebook Gem with Rails and need a profile pick on my app for each user.
Is it as simple as retrieveing the Name of the user from facebook with the Gem, or does it need to be uploaded to Amazon S3 servers etc.?
My user model:
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
Can't find a clear answer.
Updated: In my show page it only shows the url:
<b>IMAGE:</b> <%= @user.image %>
Thanks
It is simple to do. And you don't require to store image on your server. You can simply fetch it from facebook.
Here is how I do it:
Add an image
field in your User
model:
rails generate migration addImageToUsers image:string
Add it attr_accessible
list.
Then in your above method, add following listing for image:
user.image = auth.info.image
This is the direct url of where facebook stores the image of the user.
You can inspect
your auth
hash to study different size of user image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With