fig*_*dig 2 authentication authorization facebook ruby-on-rails omniauth
我正在使用omniauth-facebook gem,它完美无缺,除了个人资料图片不会显示; 当我输入代码image_tag current_user.image.to_s或image_tag current_user.image显示文本(说图片?类型=正常,正方形,大)而不是图片本身时,而不是显示图片.
omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :developer unless Rails.env.production?
provider :facebook, '166053726877178', 'df9249e9b70ef047e7a9456c7ebf9632',
:image_size => 'square'
end
Run Code Online (Sandbox Code Playgroud)
和user.rb
class User < ActiveRecord::Base
attr_accessible :email, :image, :name, :nickname, :provider, :uid
has_many :pictures
def self.create_with_omniauth(auth)
create! do |user|
user.provider = auth["provider"]
user.uid = auth["uid"]
user.name = auth["info"]["name"]
user.email = auth["info"]["email"]
user.nickname = user.email.split("@").first
user.image = auth["info"]["image"]
end
end
acts_as_voter
end
Run Code Online (Sandbox Code Playgroud)
事情是,使用这种类型的代码它可以在以前的应用程序上工作,但它在这里不起作用.提前致谢
获取用户的图像使用这些代码代替每种类型的Facebook个人资料图像
def largeimage
"http://graph.facebook.com/#{self.uid}/picture?type=large"
end
def normalimage
"http://graph.facebook.com/#{self.uid}/picture?type=normal"
end
Run Code Online (Sandbox Code Playgroud)
def smallimage" http://graph.facebook.com/# {self.uid}/picture?type = small"end
在你的意见
<%= image_tag(current_user.largeimage)%>
Run Code Online (Sandbox Code Playgroud)
等等