# Calling remote url application from controller

**URL:** <https://www.ruby-forum.com/t/calling-remote-url-application-from-controller/182875>\
**Category:** Rails\
**Created:** [February 4, 2010, 7:02am UTC](https://www.ruby-forum.com/t/calling-remote-url-application-from-controller/182875 "2010-02-04T07:02:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [February 4, 2010, 7:02am UTC](https://www.ruby-forum.com/t/calling-remote-url-application-from-controller/182875/1 "2010-02-04T07:02:20Z")

</div>

I have two rails application.  
On clicking a link on Application 1’s index.html.rb page I wish to do  
some processing like retreiving info about the selected record from DB.  
and then make a call to a different rails application.  
Do I need to write code in my view using helper functions or I can do  
this in controller.  
I wish to do this in controller… as it will mean a cleaner code in  
view.  
Is there some dispatch mechanism available in Rails controller.

---

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [February 4, 2010, 10:55am UTC](https://www.ruby-forum.com/t/calling-remote-url-application-from-controller/182875/2 "2010-02-04T10:55:01Z")

</div>

What exactly does “make a call to a different rails application” mean?

---

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [February 4, 2010, 12:01pm UTC](https://www.ruby-forum.com/t/calling-remote-url-application-from-controller/182875/3 "2010-02-04T12:01:01Z")

</div>

Sharagoz – wrote:

> What exactly does “make a call to a different rails application” mean?

For example  
I wish to call [www.google.com](http://www.google.com) with some parameters from my rails  
application then what should I do.  
I am firing some soap requests to get those input parameters for google.  
Hence I need to write some code in my controller.  
Something like I am calling show function of scaffold generated project  
and there I am calling [google.com](http://google.com) iso default show.html created by  
scaffold

---

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [February 4, 2010, 12:38pm UTC](https://www.ruby-forum.com/t/calling-remote-url-application-from-controller/182875/4 "2010-02-04T12:38:30Z")

</div>

Then you can use ‘net/http’ to send a regular http request, like so:

require ‘net/http’

connection = Net::HTTP.new(“[www.google.com](http://www.google.com)”)  
response = “”  
connection.start do |http|  
req =  
Net::HTTP::Get.new(“/#hl=en&source=hp&q=ruby+on+rails&fp=c26c79a56c95bda8”)  
response = http.request(req)  
end  
#do something with response

This can of course be put in the controller, but also the model if that  
suits you better.

---

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [February 4, 2010, 12:42pm UTC](https://www.ruby-forum.com/t/calling-remote-url-application-from-controller/182875/5 "2010-02-04T12:42:48Z")

</div>

Sharagoz – wrote:

> Then you can use ‘net/http’ to send a regular http request, like so:
> 
> require ‘net/http’
> 
> connection = Net::HTTP.new(“[www.google.com](http://www.google.com)”)  
> response = “”  
> connection.start do |http|  
> req =  
> Net::HTTP::Get.new(“/#hl=en&source=hp&q=ruby+on+rails&fp=c26c79a56c95bda8”)  
> response = http.request(req)  
> end  
> #do something with response
> 
> This can of course be put in the controller, but also the model if that  
> suits you better.

How can I open the page in a new browser.

---

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [February 4, 2010, 1:12pm UTC](https://www.ruby-forum.com/t/calling-remote-url-application-from-controller/182875/6 "2010-02-04T13:12:21Z")

</div>

I see. Can’t you just put :popup =\> true on the link in the view, and  
then use a redirect\_to in the controller?

---

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [February 5, 2010, 6:30am UTC](https://www.ruby-forum.com/t/calling-remote-url-application-from-controller/182875/7 "2010-02-05T06:30:24Z")

</div>

Sharagoz – wrote:

> I see. Can’t you just put :popup =\> true on the link in the view, and  
> then use a redirect\_to in the controller?

Thanks. The solution works as it opens the required page.

---

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [February 4, 2010, 12:54pm UTC](https://www.ruby-forum.com/t/calling-remote-url-application-from-controller/182875/8 "2010-02-04T12:54:22Z")

</div>

Prashant Thakur wrote:

> Sharagoz – wrote:
> 
> > Then you can use ‘net/http’ to send a regular http request, like so:
> > 
> > require ‘net/http’
> > 
> > connection = Net::HTTP.new(“[www.google.com](http://www.google.com)”)  
> > response = “”  
> > connection.start do |http|  
> > req =  
> > Net::HTTP::Get.new(“/#hl=en&source=hp&q=ruby+on+rails&fp=c26c79a56c95bda8”)  
> > response = http.request(req)  
> > end  
> > #do something with response
> > 
> > This can of course be put in the controller, but also the model if that  
> > suits you better.
> 
> How can I open the page in a new browser.

Basically I wish to open the 2nd page by specifying its url and  
parameters in a different window by clicking a link in first application  
this link will call the controller function where soap requests will be  
sent to server and based on that reponse I open a new website with  
parameters.
