2
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='

我怎么解决这个问题?我等你的想法。提前致谢。

4

1 回答 1

1

看起来您可能正在使用旧版本的omniauth-identity。大约一年前,omniauth github 页面上有一个提交,似乎解决了您遇到的问题。

https://github.com/intridea/omniauth-identity/commit/7efa2ae9fd44f27df09e167b5a93a62332512e0c

尝试将 gem 更新到最新版本,看看它是否效果更好。

于 2014-02-01T03:25:39.973 回答