title: How to use a custom confirmations URL in Devise
body: <p>I'm looking for a way to use a URL provided as a parameter in the <code>POST</code> request to create a user as the confirmation URL for confirming my Devise user model. The use case is that I have a rails application acting as an API for a frontend react app (setup using webpack) and I want the URL in the confirmations instructions email sent to the user to link to the frontend app, which would then send an API request to the backend to <em>manually</em> confirm the user, instead of the user visiting my backend API URLs themselves.</p>
  
  <p>I want it so that the backend could potentially be used with other clients in the future, so the URL to be used must be variable. Currently I'm trying to pass it in the API request to create the user, and then somehow I would need a way to get this variable into the Devise mailer.</p>
  
  <p>The end goal looks something like this:</p>
  
  <pre class="lang-erb prettyprint-override"><code># app/views/devise/mailer/confirmation_instructions.html.erb
  &lt;p&gt;Welcome &lt;%= @email %&gt;!&lt;/p&gt;
  
  &lt;p&gt;You can confirm your account email through the link below:&lt;/p&gt;
  
  &lt;p&gt;&lt;%= link_to 'Confirm my account', @custom_confirmation_url ?  "#{@custom_confirmation_url}#{@token}" : confirmation_url(@resource, confirmation_token: @token) %&gt;&lt;/p&gt;
  </code></pre>
  
  <p>where <code>@custom_confirmation_url</code> is the variable holding the value of the URL passed into the <code>POST</code> request to register a new user.</p>
  
  <p>I was potentially thinking of simply redirecting the user to my frontend after the confirmation, with something like <a href="https://stackoverflow.com/questions/10926626/how-to-make-devise-redirect-after-confirmation">this</a> but I don't see how I'd make it work with multiple frontend clients, if I went that route.</p>
  
  <p>I'm open to thoughts on whether or not this approach is even worth considering, or if there's a more stylistically correct way of accomplishing this.</p>