title: Force a Rails controller to return a Rack::Response
body: <p>I have a gem responsible for handling off-site payments for my users. Given an amount and a payment gateway, it determines how to redirect to the gateway's payment page. The redirection can be via GET or an auto-submitted POST form, with various headers.</p>
  
  <p>I need it to be compatible with Sinatra and other Rack frameworks, so it returns a Rack::Response.</p>
  
  <p>However, I have trouble telling my Rails controller that this <strong>is</strong> the response I want to send the user, and that it should just return it.</p>
  
  <p>I can integrate it easily in Sinatra :</p>
  
  <pre><code>get '/pay' do
    rack_response = Rack::Response.new(['Hello'], 200, {'Content-Type' =&gt; 'text/plain'})
    return rack_response.to_a
  end
  </code></pre>
  
  <p>The following seems to work in Rails 4 :</p>
  
  <pre><code># test_controller.rb
  def pay
    rack_response = Rack::Response.new(['Hello'], 200, {'Content-Type' =&gt; 'text/plain'})
  
    self.response = ActionDispatch::Response.new(*rack_response.to_a)
    self.response.close
    return
  end
  </code></pre>
  
  <p>However I cannot find an elegant way to make it work in a <strong>Rails 3.2</strong> app. Am I missing something?</p>