Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9234513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:48:28+00:00 2026-06-18T06:48:28+00:00

I am trying to use Mongoid instead of SQLite for my app. so, my

  • 0

I am trying to use Mongoid instead of SQLite for my app.

so, my code looks like as follows:

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

so,

Previously when I was using ActiveRecord, I was able to authenticate user by the following function :

 def authenticate(email, submitted_password)
-      user = find_by_email(email)
-      (user && user.has_password?(submitted_password)) ? user : nil

But now, authenticate function fails by saying that :

undefined method `has_password?' for #<Array:0xbcc55b4>

Am I missing any tiny detail for using Mongoid ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:48:30+00:00Added an answer on June 18, 2026 at 6:48 am

    this line user = User.where(email:email_id) in Mongoid returns criterion which is an array so for selecting one user you have to replace it with user = User.where(email:email_id).first which will return only one document and on which you can run the method has_password?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that looks like this: class SearchService include Mongoid::Document key :name,
I'm trying to use the pdf-reader gem (https://github.com/yob/pdf-reader) on my app (RoR with Mongoid).
I was writing a Blog like application Using Rails3/Mongoid, and now trying to use
I am trying use a Java Uploader in a ROR app (for its ease
trying to use hibernate with my web app and getting following exception: Initial SessionFactory
This is simple enough. I'm trying to use mongoid's 'after_destroy' callback to do some
I'm trying to use the Mongoid / Devise Rails 3.1 template ( Mongoid and
I've been trying to use Mongoid with Rails on Ubuntu. I have installed mongoDB
i'm trying to use Mongoid with rails 3.2.2, i've added: gem mongoid, ~> 2.4
I just removed my database.yml because I'm trying to use Mongoid, and now I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.