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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:18:13+00:00 2026-05-19T23:18:13+00:00

Now I realise this topic has been covered many times before. However there did

  • 0

Now I realise this topic has been covered many times before. However there did not appear to be a solution that wanted to make the current password field exempt only when the password in the database was blank.

I currently have the password required in my user model like:

def password_required?
  (authentications.empty? || !password.blank?) && super
end

Then I copied the update function across into my registrations controller:

def update
  if resource.update_with_password(params[resource_name])
    set_flash_message :notice, :updated
    sign_in resource_name, resource, :bypass => true
    redirect_to after_update_path_for(resource)
  else
    clean_up_passwords(resource)
    render_with_scope :edit
  end
end

I just don’t know how to go about ensuring that devise does not need a password when editing a blank password, do I also need to remove the current_password field from the view and do this?

<% if current_user.password_required? %>
  <p><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
  <%= f.password_field :current_password %></p>
<% end %>
<p><%= f.submit "Update" %></p>

Any suggestions would be great on this as I am sure I am overlooking something but I am still new to Rails on a whole. Thanks!

  • 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-05-19T23:18:13+00:00Added an answer on May 19, 2026 at 11:18 pm

    Okay so I have finally figured this out!

    Add the following to your class RegistrationsController < Devise::RegistrationsController

    def update
      if resource.update_with_password(params[resource_name])
        set_flash_message :notice, :updated
        sign_in resource_name, resource, :bypass => true
        redirect_to after_update_path_for(resource)
      else
        clean_up_passwords(resource)
        render_with_scope :edit
      end
    end
    

    Then the following to your User model:

    def update_with_password(params={})
      current_password = params.delete(:current_password) if !params[:current_password].blank?
    
      if params[:password].blank?
        params.delete(:password)
        params.delete(:password_confirmation) if params[:password_confirmation].blank?
      end
    
      result = if has_no_password?  || valid_password?(current_password)
        update_attributes(params) 
      else
        self.errors.add(:current_password, current_password.blank? ? :blank : :invalid)
        self.attributes = params
        false
      end
    
      clean_up_passwords
      result
    end
    
    def has_no_password?
      self.encrypted_password.blank?
    end
    

    The only thing I was slightly confused about is that in the edit view:

    <% if !current_user.has_no_password? %>
    

    I wrapped it in that if, I would have thought it would have been:

    <% if current_user.has_no_password? %>
    

    If anyone can see anything to improve my code or a different, more efficient way let me know!

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

Sidebar

Related Questions

I realize there have been a few other questions on this topic, and the
I know that there have been plenty of topics describing this topic but I
I have been working on this tidy-up-messy-html tags with DOM, but now I realise
So Heroku has been down all day, of course I didn't realise this until
Having read some postings here about this topic, I realize that there are quite
I realise this is quite a common one, but I've been unable to rectify
there are already some questions on this topic. Unfortunately none of them helped me
UPDATED: I realise now that I've been misreading the diff, and I have a
I asked this question in the restkit google group, but realize now that it
Now this isn't a question as to which of the technologies is better, since

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.