The link of the twitter icon obtained by logging in to twitter will be cut off immediately, so save it in s3.
https://qiita.com/puremoru0315/items/f1d459b663fd3b715dee
The above article was easy to understand
The following process is written in omniauth
user.rb
class User < ApplicationRecord
mount_uploader :image_url, ImageUploader
#If there is a user related to the argument, it is returned, and if it exists, a new one is created.
def self.find_or_create_from_auth_hash(auth_hash)
#Substitute each data acquired by OmniAuth
provider = auth_hash[:provider]
uid = auth_hash[:uid]
nickname = auth_hash[:info][:nickname]
image = auth_hash[:info][:image]
User.find_or_initialize_by(provider: provider, uid: uid) do |user|
if user.new_record?
user.nickname = nickname
user.remote_image_url = image_url
user.save
end
end
end
end
find_or_initialize_by gets the user if it is looking for it, and creates a new one if it doesn't. Unlike find_or_create_by, find_or_create_by even saves. If you want to insert only new registration processing, use find_or_initialize_by, which allows you to save after conditional branching whether to create a new one with new_record ?.
https://github.com/carrierwaveuploader/carrierwave#uploading-files-from-a-remote-location
The following processing is done in image saving
--Get the icon url from twitter --Dl the image from that url --And save the dropped image in s3
This process can be easily done with the remote_xxxx_url method.
Recommended Posts