Sha256: 42d51055201d282ef58124f976c75b65ff2ebce3bf674743f1e8022c3e4846ea
Contents?: true
Size: 1.02 KB
Versions: 5
Compression:
Stored size: 1.02 KB
Contents
class OauthAccessCard < ApplicationRecord belongs_to :user_card after_create :download_avatar after_update :check_card_avatar def check_card_avatar # при смене авы в соцсети if saved_change_to_attribute?(:photourl) download_avatar end # при переносе соц.скрепы на другого юзера(мутация ролей) переставление ему авы if saved_change_to_attribute?(:user_card_id) self.user_card.set_active_card download_avatar end end # аватару юзеру после создания соц.скрепы def download_avatar begin if self.photourl.present? image_url = self.photourl f = open(image_url) file = Tempfile.new [File.basename(URI.unescape image_url), '.jpg'] file.binmode file.write f.read file.rewind self.user_card.userable.create_avatar(uploaded_file: file) file.close file.unlink end rescue end end end
Version data entries
5 entries across 5 versions & 1 rubygems