Forum: Ruby on Rails Call between controllers

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
D5d40fd4ce9ea90df473104eaf4007bd?d=identicon&s=25 Scott N-H (frogstarr78)
on 2006-12-27 01:43
Can anyone direct me to a way that I can make an HTTP request to another
controller from inside a controller?


AnApplicationController < ActionController::Base

  def listenForAuthControllerData
    ... do some stuff w/ the data...


AuthController < ActionController::Base

  def login authentication stuff...
    ...send data to AnApplicationController...



I've seen reference to not using webrick since it doesn't handle
multi-threading. I have had some success w/ forking an http request:

Process.fork {
  req =
  req.set_form_data({"abc" => "123"})
  requester =, uri.port).request { |http|

...but the problem then is that the session's do not match when I try to
get the data back from the receiving(AnApplicationController)

I had similarly marginal success when trying to use DRb. I was able to
get the data back, however, this solution
1) Introduced another point of failure in security in what you might
have noticed is supposed to be a secure system.
2) A really complicated system.
3) Doesn't feel railsy. (actually neither of these solutions do although
I prefer the Fork {HTTP::Request} method better.)

I'm not worried about getting the data back from the requesting
Controller. Just the receiving controller.
8984c514dc77aaf6b04fc4fd8359584c?d=identicon&s=25 boboroshi (Guest)
on 2006-12-27 05:27
(Received via mailing list)
Wouldn't you do this kind of login with filters

before_filter :login

return_back_or_defalt etc etc?
D5d40fd4ce9ea90df473104eaf4007bd?d=identicon&s=25 Scott N-H (frogstarr78)
on 2006-12-27 16:57
boboroshi wrote:
> Wouldn't you do this kind of login with filters
> before_filter :login
> return_back_or_defalt etc etc?

I'm summarizing the details of a larger process that's intended to be
secure from  people listening on the line. So yes that would work but it
wouldn't solve the problem in the manner in which I'm trying to address
86e084334c00a932a3675adbf769de67?d=identicon&s=25 Paul Corcoran (Guest)
on 2006-12-27 17:34
(Received via mailing list)
It's unclear to me if these two controllers are running on the same
machine or not since you referenced DRb. If they are running on the
same machine how do you instantiate "AnApplicationController"? That is,
Rails instantiates the controller for each incoming request and from
your example that would appear to be "AuthController".

Could you simply do Of
course, this would require setup and tear down for each invocation.
Another alternative MIGHT be to instantiate it one time and store it in
a class variable. If you have multiple instances of the Ruby
interpreter running on your server though that might not work depending
on the requirements of your application.

D5d40fd4ce9ea90df473104eaf4007bd?d=identicon&s=25 Scott N-H (frogstarr78)
on 2006-12-28 17:51
No actually they would be on seperate machines.
The idea is that AnApplicationController is any old rails application.
The AuthController is the single sign-on for different
"AnApplicationController"'s. So in the AnApplicationController, we
handle redirecting to the AuthController when necessary.

The AuthController is expected to take care of authenticating the user
then sending out the permissions to the calling application (directly),
in an attempt to prevent Session hijacking and permission modifications.
86e084334c00a932a3675adbf769de67?d=identicon&s=25 Paul Corcoran (Guest)
on 2006-12-28 19:27
(Received via mailing list)
Have you considered EventMachine? I have not worked with it yet myself
but it supports SSL and would allow you to setup a socket server in
Ruby to handle the authentication and send a response back to the
client. It's available at Rubyforge. Do a google search on it. I saw
this snippet of code that got me interested in marking it as a tool
that I will likely use when the requirements call for it:

   Create a daemon / server in 11 lines of Ruby

   require 'rubygems'
   require 'eventmachine'

   module EchoServer
     def receive_data(data)
       send_data ">>> You sent: #{data}"
       close_connection if data =~ /quit|exit/i

   EventMachine::run {
     EventMachine::start_server "", 8081, EchoServer

D5d40fd4ce9ea90df473104eaf4007bd?d=identicon&s=25 Scott N-H (frogstarr78)
on 2007-01-01 20:42
Looks cool. Unfortunately, I'm trying to say within the framework of
rails. Thanks for all the help though.
This topic is locked and can not be replied to.