# POSTing to a different website in a controller action

**URL:** <https://www.ruby-forum.com/t/posting-to-a-different-website-in-a-controller-action/105251>\
**Category:** Rails\
**Created:** [May 28, 2007, 4:24am UTC](https://www.ruby-forum.com/t/posting-to-a-different-website-in-a-controller-action/105251 "2007-05-28T04:24:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![scott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@scott](https://www.ruby-forum.com/u/scott)\
**Post date:** [May 28, 2007, 4:24am UTC](https://www.ruby-forum.com/t/posting-to-a-different-website-in-a-controller-action/105251/1 "2007-05-28T04:24:24Z")

</div>

I have a page that has form that I want to submit to one of my  
actions. However, inside of the action, I want to post to a different  
website and have the browser go to that website.

The code I found on the groups seems to indicate I should do something  
like the following. However, when I do the POST, I only see raw html  
in the browser. Anyone have a suggestion on how to do this?

Here’s the action in my controller:

def pre\_place\_order  
parameters = Hash.new  
parameters[‘business’] = Variable::paypal\_business\_account  
parameters[‘upload’] = “1”  
parameters[‘cmd’] = “\_cart”  
parameters[‘redirect\_cmd’] = “\_xclick”  
parameters[‘return’] = “http://#{Variable::server\_hostname}/  
place\_order”

```
idx = 0
for item in @cart.shopping_cart_items do
  idx += 1
  parameters['item_name_#{idx}'] = item.product.name
  parameters['item_number_#{idx}'] = item.product.id.to_s
  parameters['amount_#{idx}'] = item.product.price. to_s

   if item.ship then
    parameters['shipping_#{idx}'] =

```

item.product.shipping\_cost  
end  
end

```
uri = URI.parse(Variable::paypal_transaction_url)
http = Net::HTTP.new(uri.host)
headers, res = http.post(uri.path, parameters)
render res

```

end

Thanks,

Scott

---

<div class="post-metadata">

**Author:** ![scott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@scott](https://www.ruby-forum.com/u/scott)\
**Post date:** [May 28, 2007, 4:54am UTC](https://www.ruby-forum.com/t/posting-to-a-different-website-in-a-controller-action/105251/2 "2007-05-28T04:54:25Z")

</div>

Try

render :text =\> res

you might also set the content type to text/html…

On May 27, 2007, at 7:23 PM, Scott wrote:

> ```
> for item in @cart.shopping_cart_items do
> 
> ```
> 
> >

Steve R.  
removed\_email\_address@domain.invalid  
[http://www.calicowebdev.com](http://www.calicowebdev.com)
