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

  • SEARCH
  • Home
  • 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 8750137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:48:51+00:00 2026-06-13T12:48:51+00:00

Hello I trying to create a reset password for my rails app; but when

  • 0

Hello I trying to create a reset password for my rails app; but when I try to save I get the following error:

Validation failed: Password can’t be blank, Password is too short
(minimum is 6 characters), Password confirmation can’t be blank

This is my user model.

class User < ActiveRecord::Base
  attr_accessible :email, :password, :password_confirmation
  has_secure_password

  before_save { |user| user.email = email.downcase }
  before_save :create_remember_token

  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false }
  validates :password, presence: true, length: { minimum: 6 }
  validates :password_confirmation, presence: true

    def send_password_reset
        self.password_reset_token = SecureRandom.urlsafe_base64
        self.password_reset_at = Time.zone.now
        self.password = self.password
        self.password_confirmation = self.password
        save!
    end

  private

    def create_remember_token
        self.remember_token = SecureRandom.urlsafe_base64
    end

end

the method “send_password_reset” doesn’t update the user and I don’t understand why is trying to save the user instead on updating just password_reset_token and the password_reset_at.

Does anybody can help me, please?

  • 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-13T12:48:51+00:00Added an answer on June 13, 2026 at 12:48 pm

    When you call save! on the model instance, it’s going to run the validations on your User model; all of them.

    There are a number of ways to skip the password validations conditionally. One is to use a Proc

    validates :password, presence: true, length: { minimum: 6 }, unless: Proc.new { |a| !a.new_record? && a.password.blank? }
    

    This will allow the User instance to be saved and will skip the validation of the :password field if it’s blank and the User is not new (already persisted to the database).

    Here is most of a password validation I use in my applications

    validates :password, confirmation: true,
                         length: {:within => 6..40},
                         format: {:with => /^(?=.*\d)(?=.*([a-z]|[A-Z]))([\x20-\x7E]){6,40}$/},
    

    Notice, you don’t need the separate validation on :password_confirmation. Instead just pass confirmation: true to the :password validator.

    Suggested Reading:

    • http://guides.rubyonrails.org/active_record_validations_callbacks.html#confirmation
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a Metro-style app following this guide for a hello, word
Hello I am trying to create a custom expandable listview, but the documentation on
Hello I am trying to create a stacked barplot using the following code: test
Hello I am trying to create some simple pagination, but my php skills are
I am trying to create my hello world windows app in WPF. What should
Hello I'm trying to save string into SQLite database, but nothing happens. I have
Hello I am trying to create a brush but I am having problem with
I am trying to create a Hello World JS Metro app on Visual Studio
I'm trying to create a very simple Hello, world program in RoR, but when
Hello i am trying to create aplication witch shows me sms in ListView but

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.