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 8000325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:45:28+00:00 2026-06-04T15:45:28+00:00

I have a User model, and authentication is provided by has_secure_password. I would like

  • 0

I have a User model, and authentication is provided by has_secure_password. I would like to implement a separate view for password edits.

Are there any decent tutorials or learning resources where I can go for more on how to best accomplish this?

My simplified model:

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

  before_save :create_remember_token

  validates :name, presence: true, length: { maximum: 50 }
  validates :email, presence: true, uniqueness: { case_sensitive: false }, format: { with: /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i }
  validates :password, :length => { :within => 6..40 }
  validates :password_confirmation, presence: true    
end

I’d like to make sure that the password validations only run when the user is editing the change_password page, and that there is a separate page for editing passwords.

I imagine I need new controller actions, like edit_password and update_password. Would I then do: validates :password, on: [:create, :update_password]?

I’m a bit stuck and would really like to browse some sample code or blog posts on this subject.

  • 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-04T15:45:30+00:00Added an answer on June 4, 2026 at 3:45 pm

    If you want to run validations only when

    1.creating the new user
    2.updating the password
    

    You can go for conditional validations.

    class User < ActiveRecord::Base
      attr_accessor :update_password
    
      validates :password, :length => { :within => 6..40 }, :if => new_record? || update_password
      validates :password_confirmation, presence: true, :if => new_record? || update_password
    end
    

    And in your controller you need to set the update_password is true.

    class PasswordsController < ActionController::Base
    
     def edit
       #You will render the password edit view here
     end
    
     def update
       @user = User.find(params[:id])
       @user.update_password = true
       @user.password = params[:password]
       @user.password_confirmation = params[:password_confirmation]
       if @user.save
          #success redirect here
       else
          render :edit
       end
     end
    
    end
    

    FYI.

    validates :password, on: [:create, :update_password]
    

    Here :create, :update_password does not means the controller actions.It means the various states of the user object. Its includes :create, :update and update_password is not valid state.

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

Sidebar

Related Questions

I have a user model that requires the user to change their password every
I have a user model on which I check to make sure that the
I have a User model and a Submission model. Each Submission has a ForeignKey
I have a User model, a Post model, and an Interest model. User has_many
I have a User model, and use an acts_as_authentic (from authlogic) on it. My
I have a User model and an Account model. The user has many accounts
I have a User model that has the following default_scope: default_scope where(account_id: Account.current_account.id) If
i have a User model and a UserMessage model (a model for holding the
I have a User model. I am trying to update a confirm attribute from
Hello I have a user model and a ratings model. Whenever a new user

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.