我正在开发一个rails应用程序,它允许用户使用omniauth通过facebook/twitter/linkedin登录。到目前为止,用户可以注册并使用身份验证创建帐户,但他们必须通过验证,因此会被转发到注册页面,在那里他们必须输入有效的名称、用户名和电子邮件。如果可能的话,我希望已经使用request.env"omniauth.auth“散列填充了这些字段。
下面是我的代码:
authentications_controller.rb
user = User.new
user.apply_omniauth(omniauth)
if user.save
flash[:notice] = "Signed in successfully."
sign_in_and_redirect(:user, user)
else
session[:omniauth] = omniauth.except('extra')
redirect_to new_user_registration_url
endregistrations_controller.rb:
def build_resource(*args)
super
if session[:omniauth]
@user.apply_omniauth(session[:omniauth])
@user.valid?
end
enduser.rb:
def apply_omniauth(omniauth)
self.name = omniauth['user_info']['name'] if name.blank?
self.email = omniauth['user_info']['email'] if email.blank?
authentications.build(:provider => omniauth['provider'], :uid => omniauth['uid'])
end这行代码:
self.email = omniauth['user_info']['email'] if email.blank?此NoMethodError中的结果:
undefined method `[]' for nil:NilClass会话: omniauth在apply_omniauth方法中从注册控制器传递到omniauth。如何访问此会话中的名称和电子邮件?
谢谢
发布于 2012-03-26 04:45:12
与omniauth'info'
将此代码放在回调控制器的第一行:
render :text => "“+ env"omniauth.auth".to_yaml和returnNow尝试登录,您将能够很好地查看返回的嵌套散列的散列。
https://stackoverflow.com/questions/9863258
复制相似问题