Rails注册多种方式

时间:2015-11-13 05:35:51

标签: ruby-on-rails

在我正在开发的当前应用中,我可以使用Facebook和Google+注册。但是,当我添加了仅使用常规电子邮件注册的功能时,我收到了此错误,我将非常感谢您的帮助...

以下是我的一些代码

while(fgets(savedString, 100, stream)!=NULL){
...
}

因此,当尝试使用电子邮件注册时,就会发生这种情况!

enter image description here

我猜错了,因为我正在调用#SessionsController def create @user = User.from_omniauth(env["omniauth.auth"]) # session[:user_id] = @user.id # redirect_to root_path @user = User.find_by_email params[:email] if @user && @user.authenticate(params[:password]) session[:user_id] = @user.id redirect_to root_path else flash[:alert] = "Wrong email or password" render :new end end #user.rb class User < ActiveRecord::Base has_secure_password def self.from_omniauth(auth) where(provider: auth.provider, uid: auth.uid).first_or_create do |user| user.provider = auth.provider user.uid = auth.uid user.name = auth.info.name user.email = auth.info.email user.oauth_token = auth.credentials.token user.oauth_expires_at = Time.at(auth.credentials.expires_at) user.image = auth.info.image user.gender = auth.extra.raw_info.gender user.location = auth.extra.raw_info.location.name user.location = auth.extra.raw_info.locale # user.url = auth_hash['info']['urls'][user.provider.capitalize] user.save end end 并且我没有通过提供商,在这种情况下我不需要使用。

1 个答案:

答案 0 :(得分:0)

您可以考虑重新开始 - 使用https://github.com/plataformatec/devise,然后在此基础上添加OmniAuth(https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview)。