我使用的设计为用户和“omniauth Facebook的”所以我user.rb我有写这个函数:
DEF self.find_for_facebook_oauth(AUTH,signed_in_resource =无)用户= User.where(:提供商=> auth.provider,:UID => auth.uid) . 首先,除非用户
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 :: OmniauthCallbacksController#Facebook的Mysql2 ::错误:数据太长,在行1列'education':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:in
facebook'
omniauth_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
结束
语言仍然空着!
你也知道如何获取地址或其他数据谢谢 .