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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:24:09+00:00 2026-05-29T16:24:09+00:00

Using Ruby 1.9.3 and bcrypt-ruby 3.0.1 I’m working on the Depot app from the

  • 0

Using Ruby 1.9.3 and bcrypt-ruby 3.0.1

I’m working on the Depot app from the Agile Web Development book, and I’m having issues authenticating a user’s current password in order for them to change their password.

My Users model:

class User < ActiveRecord::Base
  validates :name, presence: true, uniqueness: true
  attr_accessible :name, :password, :current_password, :password_confirmation
  has_secure_password

  after_destroy :ensure_an_admin_remains

  private
    def ensure_an_admin_remains
      if User.count.zero?
        raise "Can't delete last user"
      end
    end
end

My update method in the Users controller looks like this:

  def update
    @user = User.find(params[:id])
    if @user.authenticate(params[:current_password])
      params[:user].delete :current_password
      respond_to do |format|
        if @user.update_attributes(params[:user])
          format.html { redirect_to users_url, notice: "User #{@user.name} was successfully updated." }
          format.json { head :no_content }
        else
          format.html { render action: "edit" }
          format.json { render json: @user.errors, status: :unprocessable_entity }
        end
      end
    else
      redirect_to edit_user_path(@user), notice: "Current password is incorrect."
    end
  end

My users form looks like this:

<%= form_for(@user) do |f| %>
  <% if @user.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
      <ul>
      <% @user.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

    <fieldset>
        <legend>Enter User Details</legend>
        <div>
        <%= f.label :name %><br />
        <%= f.text_field :name, size: 40 %>
      </div>
        <% if params[:action] == :edit %>
            <div>
                <label for="old_password">Old Password:</label>
                <%= password_field_tag :current_password, params[:current_password]%>
            </div>
        <% end %>
        <div>
        <%= f.label :password, 'Password' %><br />
        <%= f.password_field :password, size: 40 %>
      </div>
        <div>
            <%= f.label :password_confirmation, 'Confirm' %>
            <%= f.password_field :password_confirmation, size: 40%>
        </div>
      <div>
        <%= f.submit %>
      </div>
    </fieldset>
<% end %>

The issue seems to be with the @user.authenticate(params[:current_password]) line.
I am puzzled, because I think the authentication is within the scope for the param, and also because this very method on the console does pass.

  • 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-29T16:24:09+00:00Added an answer on May 29, 2026 at 4:24 pm

    I think it should be if @user.authenticate(params[:user][:current_password])

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

Sidebar

Related Questions

Using Ruby (newb) and Regex, I'm trying to parse the street number from the
I am implementing a validation scheme and am using the bcrypt-ruby gem. require 'bcrypt'
I am using RUBY to screen scrap a web page (created in asp.net) which
I am using Ruby on Rails 3.0.7 and I am migrating from Prototype to
I'm using Rails 3.0.3, and I have changed the mysql adapter from ruby-mysql to
I'm working through Michael Hartl's Ruby on Rails tutorial on http://ruby.railstutorial.org . I'm having
I am using Ruby code to calculate sum from the array returned by Mongoid.
Using Ruby I'm trying to split the following text with a Regex ~foo\~\=bar =cheese~monkey
using Ruby on Rails 2.3.2, since I already created Scaffold for Story, so instead
Using Ruby/RoR - The year is a string in the model/view. How do I

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.