Search code examples
ruby-on-rails-3restroutesputemail-confirmation

Rails: email confirmation RESTful (PUT) URL in mailer


Rolling my own email confirmation from scratch. Struggling with how to generate the proper routing for my confirmations_controller.

new user gets sent an email with link back to app to 'verify' address.

My thought is it should be a PUT action because it WILL make changes to the DB. But, clicking on a link in an email won't submit a 'put' action...or will it? I must be missing something, my own ignorance aside.

#config/routes.rb
...
resources :confirmations, only: [:update]

confirmation_url(user.email_token) generates valid url: http://localhost:3000/confirmations/ArELEOejYlqbRXdJPavhrp but when clicking on that link it is received by app as a 'get' request.

How should I be handling this?


Solution

  • What format is your email? If its plain text, it will be a GET. That itself is not a problem for updating the activation page. You could also open a page (with GET) and let them click on a button for final submit (not uncommon).

    However, updating through a GET would not bother me for this specific function.

    example:

    # routes.rb
    get 'confirmations/:id/confirm' => 'Confirmations#confirm'
    
    # confirmations.rb
    class ConfirmationsController < ApplicationController
    
      def confirm
        # handle the get data here (switch aa flag for the email account)       
       end
    end