0
我不知道如何管理更新通過Omniauth註冊的用戶數據 - 例如,如果我在twitter上更新我的profil圖片,則會顯示profil圖片我的網絡應用程序未更新,並會顯示損壞。使用omniauth(微博)登錄時更新用戶數據
我的用戶模型設置如下:
應用程序/模型/ user.rb
class User < ActiveRecord::Base
has_merit
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
extend FriendlyId
friendly_id :name, use: :slugged
def should_generate_new_friendly_id?
new_record?
end
devise :database_authenticatable, :registerable,:omniauthable,
:recoverable, :rememberable, :trackable, :validatable
validates :email, presence: true,
uniqueness: true
has_many :pins, :dependent => :destroy
has_many :comments, :dependent => :destroy
has_many :votes, dependent: :destroy
has_many :upvoted_pins, through: :votes, source: :pin
has_many :rewards, dependent: :destroy
has_many :rewarded_pins, through: :rewards, source: :pin
has_many :badges
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.nickname
user.image = auth["info"]["image"]
user.description = auth.info.description
end
end
def self.new_with_session(params, session)
if session["devise.user_attributes"]
new(session["devise.user_attributes"]) do |user|
user.attributes = params
user.valid?
end
else
super
end
end
def password_required?
super && provider.blank?
end
def update_with_password(params, *options)
if encrypted_password.blank?
update_attributes(params, *options)
else
super
end
end
end
嘿我試了很多東西來實現這一點,但它仍然在工作 - 我不能得到te配置文件圖片更新omniauth ...任何想法? – zacchj 2014-09-06 13:20:36