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.
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.
I think this function (which I have copied below from the devise ruby docs) is going to help.
#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
My problem is that I don't understand how it works or how to incorporate it in my app.
Do I add it to my user model (just copy & 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?
If I do that, what name do I give to the controller call?
In user.rb I have tried:
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
In user controller - update action, I have tried:
if @user.update(user_params)
user.postpone_email_change_until_confirmation_and_regenerate_confirmation_token
Im clearly trying to do this incorrectly. What's not clear to me is how I'm supposed to use this function.
Can anyone see where I've gone wrong?