1

我为用户和'omniauth-facebook'使用设计,所以在我的user.rb中我写了这个函数:

def self.find_for_facebook_oauth(auth, signed_in_resource=nil) user = User.where(:provider => auth.provider, :uid => auth.uid).first 除非用户

user = User.create(name: auth.extra.raw_info.first_name,
                   surname: auth.extra.raw_info.last_name,
                   provider: auth.provider,
                   uid: auth.uid,
                   email: auth.info.email,
                   password: Devise.friendly_token[0, 20],
                   state: auth.extra.raw_info.locale.gsub(/_/, '-'),
                   gender: auth.extra.raw_info.gender,
                   language: auth.extra.raw_info.language,
                   bio: auth.extra.raw_info.bio,
                   work: auth.extra.raw_info.work || { },
                   education: auth.extra.raw_info.education

)
end
 user
end

除了教育和工作 ActiveRecord::StatementInvalid in Users::OmniauthCallbacksController#facebook Mysql2::Error: Data too long for column 'education' at row 1: INSERT INTO users( address, bio, created_at, current_sign_in_at, current_sign_in_ip, education,email

app/models/user.rb:23:in find_for_facebook_oauth' app/controllers/users/omniauth_callbacks_controller.rb:4:infacebook'

omn​​iauth_callbacks_controller.rb:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
  @user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)

  if @user.persisted?
    flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
    sign_in_and_redirect @user, :event => :authentication
  else
    session["devise.facebook_data"] = request.env["omniauth.auth"]
    redirect_to new_user_registration_url
  end
end

结尾

而语言仍然是空的!

您还知道如何获取地址或其他数据,谢谢。

4

0 回答 0