title: Redirect Externally After POST Request (Ruby on Rails 7)
body: <p>In Rails 7, I am trying to use <code>redirect_to</code> to redirect the browser to an external website after that browser submits a POST request.</p>
  <p>I have a view with a form:</p>
  <pre class="lang-html prettyprint-override"><code>&lt;!-- view/articles/new.html.erb --&gt;
  &lt;h1&gt;New Article&lt;/h1&gt;
  &lt;%= form_with model: @article do |form| %&gt;
    &lt;%= form.label :mystring %&gt;
    &lt;%= form.text_field :mystring %&gt;
  &lt;% end %&gt;
  </code></pre>
  <p>A controller:</p>
  <pre class="lang-rb prettyprint-override"><code>class ArticlesController &lt; ApplicationController
    def create
      # Do some active record stuff...
      redirect_to 'https://google.com', allow_other_host: true
    end
  end
  </code></pre>
  <p>And my routes:</p>
  <pre class="lang-rb prettyprint-override"><code>Rails.application.routes.draw do
    resources :articles
  end
  </code></pre>
  <p>I go to http://localhost:3000/articles/new, and enter the data into the form.  After submitting, the page simply reloads (in other words, I am still on http://localhost:3000/articles/new).  I do not get redirected to <a href="https://google.com" rel="nofollow noreferrer">https://google.com</a>, as I expect.</p>
  <p>Doing the POST request in <a href="https://insomnia.rest/" rel="nofollow noreferrer">Insomnia</a>, the redirect works without any issues.</p>
  <p>Also, I tested what I believe would be the way to accomplish this in NodeJS (using Express), with the following code.  This redirect works in both browsers without any issue.</p>
  <pre><code>app.post('/articles/create', function(req, res){
    res.writeHead(302, {
      'Location': 'https://google.com'
    });
    res.end();
  });
  
  </code></pre>
  <p>From my understanding, Rails is just writing a 'Location' header, same as I am doing manually in Express.  Rails does seem to write quite a few more headers than Express, however, so maybe one of those is what's causing the issue.</p>
  <p>Any help would be much appreciated.  Thank you!</p>