Ruby on rails 无法在请求之间保留新对象-RoR
在我的应用程序中,我有一个twitter和facebook登录名,但是在他们首次注册twitter或facebook后,我需要提示密码和电子邮件。我正在使用omniauth gems,我的控制器/用户模型如下所示:Ruby on rails 无法在请求之间保留新对象-RoR,ruby-on-rails,activerecord,omniauth,Ruby On Rails,Activerecord,Omniauth,在我的应用程序中,我有一个twitter和facebook登录名,但是在他们首次注册twitter或facebook后,我需要提示密码和电子邮件。我正在使用omniauth gems,我的控制器/用户模型如下所示: //socials_controller.rb def create #render text: request.env['omniauth.auth'].to_yaml and return @user = User.from_omn
//socials_controller.rb
def create
#render text: request.env['omniauth.auth'].to_yaml and return
@user = User.from_omniauth(request.env['omniauth.auth'])
if(@user.email == nil)
redirect_to patient_login_entry_url(@user)
elsif @user.confirmed
log_in @user
redirect_to @user
else
flash[:danger] = "Bir hata olustu."
redirect_to root_url
end
end
def login_entry
@patient = Patient.find(params[:id])
end
def update_social
@patient = Patient.find(params[:id])
if @patient.update_attributes(user_params)
SendVerificationEmailJob.perform_later @patient
flash[:success] = "Aktivasyon için #{@patient.email} adresinizi kontrol ediniz."
redirect_to root_url
else
flash[:danger] = "Bilgilerinizi kontrol edip tekrar deneyiniz."
redirect_to patient_login_entry_url(@patient)
end
end
我的from_omniauth方法是:
//user.rb
has_secure_password
class << self
def from_omniauth(auth_hash)
if exists?(uid: auth_hash['uid'])
user = find_by(uid: auth_hash['uid'])
else
user = find_or_create_by(uid: auth_hash['uid'], provider: auth_hash['provider'], type: 'Patient')
user.location = get_social_location_for user.provider, auth_hash['info']['location']
if auth_hash.provider == 'facebook'
user.avatar = User.process_uri(auth_hash['info']['image'])
user.name = auth_hash['extra']['raw_info']['first_name']
user.surname = auth_hash['extra']['raw_info']['last_name']
user.email = auth_hash['extra']['raw_info']['email']
user.gender = auth_hash['extra']['raw_info']['gender']
elsif auth_hash.provider == 'twitter'
user.avatar = auth_hash['info']['image']
user.name = auth_hash['info']['name']
end
user.url = get_social_url_for user.provider, auth_hash['info']['urls']
user.save!
end
user
end
//user.rb
有安全的密码吗
类,您可以使用user.save保存它并绕过变量!(validate:false)
您可以在两个请求之间的会话中存储密码。