我正在开发一个应用程序,您可以在其中通过 facebook 登录或注册。出于这个原因,我有一个可以是 facebook 图像或上传图像的图像,但我不知道如何将它放入模型中。
我的模型:
class User < ActiveRecord::Base
attr_accessible :name, :password, :password_confirmation, :big_image, :image, :mini_image
validates_confirmation_of :password
validates_presence_of :password, :on => :create, :unless => :from_facebook
validates_presence_of :name
validates_uniqueness_of :name
unless :from_facebook
mount_uploader :big_image, ImageUploader
end
def from_facebook
self.provider == "facebook"
end
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.big_image = auth.info.image.gsub("=square","=large")
user.image = auth.info.image.gsub("=square","=normal")
user.mini_image = auth.info.image
user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!
end
end
end
结尾
我要更改的部分是:
unless :from_facebook
mount_uploader :big_image, ImageUploader
end
因为它不起作用。