Devise Omniauth «encrypted_password may not be NULL» для нового пользователя

Я использую Devise с Omniauth, чтобы пользователи входили в мое приложение через Facebook. Я использовал обучающие материалы Railscast, чтобы запустить его.

Если пользователь уже является участником моего сайта, аутентификация через facebook работает нормально. Проблема возникает при аутентификации нового пользователя с помощью facebook. Когда идет создание нового пользователя для моей модели User, я получаю ошибку «users.encrypted_password может быть не NULL». Я не могу понять, как передать пароль модели User из информации Facebook.

Это то, что у меня есть:

Authentations_controller.rb

class AuthenticationsController < ApplicationController
 def index
  @authentications = current_user.authentications if current_user
 end

def create
  omniauth = request.env["omniauth.auth"]
  authentication = Authentication.find_by_provider_and_uid(omniauth['provider'],   omniauth['uid'])
 if authentication
   flash[:notice] = "Signed in successfully."
   sign_in_and_redirect(:user, authentication.user)
 elsif current_user
   current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'])
   flash[:notice] = "Authentication successful."
   redirect_to authentications_url
 else
   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
   end
  end
end

user.rb

 def apply_omniauth(omniauth)
  self.email = omniauth['user_info']['email'] if email.blank?
  authentications.build(:provider => omniauth['provider'], :uid => omniauth['uid'])
 end


 def password_required?
   (authentications.empty? || !password.blank?) && super
 end

Любая помощь была бы замечательной, заранее спасибо!

9
задан lulalala 22 October 2014 в 04:30
поделиться