Ruby on rails 从ActiveRecord移动到Mongoid后无法访问方法

Ruby on rails 从ActiveRecord移动到Mongoid后无法访问方法,ruby-on-rails,mongoid,rails-activerecord,Ruby On Rails,Mongoid,Rails Activerecord,我正在尝试在我的应用程序中使用Mongoid而不是SQLite 因此,我的代码如下所示: class User include Mongoid::Document include Mongoid::Timestamps field :name, type: String field :email, type: String field :encrypted_password, type: String field :salt , type: String

我正在尝试在我的应用程序中使用Mongoid而不是SQLite

因此,我的代码如下所示:

class User 

  include Mongoid::Document
  include Mongoid::Timestamps


  field :name,  type: String
  field :email, type: String
  field :encrypted_password, type:  String
  field :salt , type: String
  field :admin , type: Boolean


  attr_accessor   :password
  attr_accessible :name, :email, :password, :password_confirmation
 .....

   def has_password?(submitted_password)
      encrypted_password == encrypt(submitted_password)
    end

  ....

 class << self
def authenticate(email_id, submitted_password)
  print "authenticate the user " + email_id
  user = User.where(email:email_id)

  if user.nil?
    return false
  else
    print "\n Check the passsword" + user.has_password?(submitted_password)

  end

end
但现在,authenticate函数失败了,原因是:

undefined method `has_password?' for #<Array:0xbcc55b4>
未定义的方法'has_password'#

我在使用Mongoid时是否遗漏了任何细节

Mongoid中的这一行
user=user.where(email:email\u id)
返回一个标准,该标准是一个数组,因此要选择一个用户,您必须将其替换为
user=user.where(email:email\u id)。首先,
它将只返回一个文档,并且您可以在其上运行方法
具有\u密码?

这一行
user=user.where(email:email\u id)
在Mongoid中返回标准,该标准是一个数组,因此选择一个用户时,您必须将其替换为
user=user.where(email:email\u id).first
只返回一个文档,您可以在其上运行方法
具有\u密码?

仍有其他问题。试图解决这些问题。谢谢你的建议。还有其他问题。试图解决这些问题。谢谢你的建议。
undefined method `has_password?' for #<Array:0xbcc55b4>