title: Agile Web Development with Rails 5.1 Playground - Ch 15 Password Trouble
body: <p>I can't figure out something in Agile Web Development with Rails, Chapter 15 - Playgrounds question 1.
  It asks <strong>Modify the user update function to require and validate the current
  password before allowing a user’s password to be changed.</strong></p>
  
  <p>I really can't understand how I can get the <em>has_secure_password</em> helper method to allow me to also seek the current password, if there is one, and see if it equals a hash before allowing a change of the password to be made.</p>
  
  <p>I'm reading along with the book and when it gets to these Playgrounds, I feel like chewing glass alot of the time.</p>
  
  <p>My _form partial looks like this:</p>
  
  <pre><code>&lt;h2&gt;Enter User Details&lt;/h2&gt;
  
    &lt;div class="field"&gt;
      &lt;%= form.label :name, 'Name:' %&gt;
      &lt;%= form.text_field :name, id: :user_name, size: 40 %&gt;
    &lt;/div&gt;
  
    &lt;% if user.password_digest %&gt;
      &lt;%= form.label :password_digest, 'Current Password' %&gt;
      &lt;%= form.password_field :password_digest, id: :password_digest, size: 40 %&gt;
    &lt;% end %&gt;
  
    &lt;div class="field"&gt;
      &lt;%= form.label :password, 'Password' %&gt;
      &lt;%= form.password_field :password, id: :user_password, size: 40 %&gt;
    &lt;/div&gt;
  
    &lt;div class="field"&gt;
      &lt;%= form.label :password_confirmation, 'Confirm:' %&gt;
      &lt;%= form.password_field :password_confirmation, 
                      id: :user_password_confirmation,
                      size: 40 %&gt;
    &lt;/div&gt;
  
    &lt;div class="actions"&gt;
      &lt;%= form.submit %&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>I check whether the user at present has a password_digest property in the the instance-variable to see whether I display the form chunk that is all decked out with password_digest symbols.</p>
  
  <p>In my user_controller's <strong>update</strong> function, looks like this</p>
  
  <pre><code>def update
      puts "update running"
      puts @user
      puts @user.name
      puts @user.password
      puts @user.password_confirmation
      respond_to do |format|
        if @user.update(update_params)
          # format.html { redirect_to @user, notice: 'User was successfully updated.' }
          format.html { redirect_to users_url, notice: "User #{@user.name} was successfully updated." }
          format.json { render :show, status: :ok, location: @user }
        else
          format.html { render :edit }
          format.json { render json: @user.errors, status: :unprocessable_entity }
        end
      end
    end
  </code></pre>
  
  <p>You'll notice the use of 'update_params'...I made another private method at the bottom of the file that differs from the standard 'user_params', I thought by substituting that into the mix I could get the whole thing to work.</p>
  
  <p>To be honest, I'm so incredibly lost. If someone could please guide me on how to do this, I would be really grateful. I've googled and stackflow searched all over and I feel like in the search to find water to douse  fire, I can only find flammable liquids, each one more reactive to heat than the last.</p>
  
  <p>Is there a repository out there that has all these extra 'Playgrounds' things done, so I can take a look at them and see what's going on?</p>