Rails 4 - Devise - Confirmable subject to approval
<p>I'm trying to learn how to read rubydocs. I'm sure there is something fundamentally basic that I have missed in trying to use these documents, but for now, I'm so frustrated that information is being presented to me, but without any form of intelligible user guide that goes along with it. </p>

<p>I want to amend my devise, so that users can nominate a group they want to join - in this case, an organisation where their email is changed to an organisation email, pending confirmation by the organisation owner.</p>

<p>I think this function (which I have copied below from the devise ruby docs) is going to help. </p>

<pre><code>#postpone_email_change_until_confirmation_and_regenerate_confirmation_token ⇒ Object (protected)

253
# File 'lib/devise/models/confirmable.rb', line 247

def postpone_email_change_until_confirmation_and_regenerate_confirmation_token
  @reconfirmation_required = true
  self.unconfirmed_email = self.email
  self.email = self.email_was
  self.confirmation_token = nil
  generate_confirmation_token
end
</code></pre>

<p>My problem is that I don't understand how it works or how to incorporate it in my app. </p>

<p>Do I add it to my user model (just copy &amp; paste) and then put a line in my user controller for the update action, so that any change of email does each of those the steps listed in the method?</p>

<p>If I do that, what name do I give to the controller call?</p>

<p>In user.rb I have tried:</p>

<pre><code> def postpone_email_change_until_confirmation_and_regenerate_confirmation_token
      @reconfirmation_required = true
      self.unconfirmed_email = self.email
      self.email = self.email_was
      self.confirmation_token = nil
      generate_confirmation_token
    end
</code></pre>

<p>In user controller - update action, I have tried:</p>

<pre><code>if @user.update(user_params)
user.postpone_email_change_until_confirmation_and_regenerate_confirmation_token
</code></pre>

<p>Im clearly trying to do this incorrectly. What's not clear to me is how I'm supposed to use this function.</p>

<p>Can anyone see where I've gone wrong?</p>