class IdentitiesController < ApplicationController
def new
@identity = Identity.new
# @identity = env['omniauth.identity']
end
end
我的注册表格是:
=simple_form_for( :identity, url: "/auth/identity/register", :html => { id: :signup_form, class: 'form-horizontal' }) do |f|
= f.error_notification
.form-inputs
.control-group
.controls
.input-prepend
span.add-on
i.icon-user
input#name placeholder="name" type="text" f.name
.control-group
.controls
.input-prepend
span.add-on
i.icon-envelope
input#email placeholder="email" type="text" f.email
.control-group
.controls
.input-prepend
span.add-on
i.icon-key
input#password placeholder="password" type="password"
.control-group
.controls
.input-prepend
span.add-on
i.icon-key
input#password_confirmation placeholder="password confirmation" type="password"
.form-actions
.control-group
.controls
= f.button :submit, :class => 'btn-primary'
我的身份模型
class Identity
include Mongoid::Document
include OmniAuth::Identity::Models::Mongoid
field :name, type: String
field :email, type: String
field :password_digest, type: String
validates_presence_of :name
validates_presence_of :email
validates_uniqueness_of :email
validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
validates_length_of :password, minimum: 8, maximum: 16
end
我使用omniauth-identity gem。我的身份模型,identities_controller和身份/新视图如上所述。当我单击注册按钮时,它会出现undefined method 'empty?' for nil:NilClass
错误。我查看了控制台和价值观帖子。它显示
NoMethodError (undefined method `empty?' for nil:NilClass):
omniauth-identity (1.1.0) lib/omniauth/identity/secure_password.rb:71:in `password='
我该如何解决这个问题?我等你的想法。提前谢谢。
答案 0 :(得分:1)
看起来您可能正在使用旧版本的omniauth-identity。大约一年前在omniauth github页面上有一个提交,似乎可以解决您遇到的问题。
https://github.com/intridea/omniauth-identity/commit/7efa2ae9fd44f27df09e167b5a93a62332512e0c
尝试将gem更新到最新版本,看看它是否更好。