title: Rails: How to confirm email address entered in text box matches current user's email address?
body: <p>I am creating a page that allows a user to delete their account/profile.  On this page, I have a text box where the user types their email address to confirm they are indeed the current user and that they want to delete their account (upon button click).  </p>
  
  <p>What I want to do is, when the user clicks the "Delete Account" button below the text box, I want to grab that text and compare it to the current user's email account.  If it matches, I want to delete the user's account.  If not, I want to flash an error message.</p>
  
  <p>I have some of the logic figured out, and I will paste what I have below.  <strong>Right now, if you click the 'Delete Account' button it deletes the user's account and redirects to the home page, and flashes a 'goodbye' message on the home page.</strong>  <em>However, there is no comparison functionality b/t current user's email and text box entry.</em>  I'm not sure if I can do this in Rails or if I will have to incorporate JavaScript.  I am using Devise and Cancan.  </p>
  
  <p>Please be as explicit as possible, I am fairly new to Rails. <strong>Thank you!</strong></p>
  
  <p>Email box and button are at /settings/profile/delete, file is 'delete.html.haml'.</p>
  
  <p><strong>The email box</strong></p>
  
  <pre><code>.field
    = label :email, 'Email Address'
    = email_field :email, 'Enter your email address', id: 'delete-email-box'
  </code></pre>
  
  <p><strong>The Delete Account Button (below email box)</strong></p>
  
  <pre><code>#confirm-delete-btn
    = link_to 'Delete Account', user_registration_path, method: :delete, data: 
     { confirm: 'Are you sure you want to delete your account? This cannot be 
     undone!' }, class: submit btn-delete'
    = link_to 'Cancel', profile_index_path, id: 'cancel-profile'
  </code></pre>
  
  <p><strong>profile_controller.rb</strong></p>
  
  <pre><code>def delete
    @user = current_user
    @profile = current_user.profile
  end
  
  def destroy
    @user = current_user
    @profile = current_user.profile
    if @profile.destroy
      @user.destroy
      redirect_to root_url, notice: "User deleted."
    else
      render_error_message
    end
  end
  </code></pre>