Using Rails MVC to handle non-HTTP requests

I’m starting to think through a webapp that allows multiple connection
types (HTTP/web, email, SMS, Twitter, etc), and I’d like to combine as
much functionality as possible. To that end, I’ve been thinking about
how to integrate the other media with Rails’ MVC. For each one, I’d
like the input to be the same as the output (that is, if I send an SMS
to the server, I get an SMS response).

I imagine creating fake MIME types for each one, and then having
foo_view.html.erb, foo_view.sms.erb, foo_view.twitter.erb, etc.

Some problems:

  1. I can’t figure out how to dispatch to a controller. For example,
    if I have a daemon thread polling for email, how do I take the
    extracted email text and use it to set up the request for the
    controller? How do I then call the controller’s handle method?

  2. Are Rails controllers really abstract enough for this? They seem
    quite tied to the AbstractRequest object, which is certainly HTTP.
    (Email has no concept of GET vs PUT or a URL, and HTTP has no concept
    of a Subject.)

  3. Would I be better off choosing a different framework? I love
    Rails, but am I trying to cut a cucumber with my golden hammer?

-Gaius

On 10/23/07, gcnovus [email protected] wrote:

  1. Would I be better off choosing a different framework? I love
    Rails, but am I trying to cut a cucumber with my golden hammer?

Instead of having the daemons try to directly invoke rails
controllers, why not have them simply make http requests themselves?
You can have controllers actions in the rails app to deal with your
(inner ) daemons.

You could use ActiveRecord perhaps together with ActionMailer to
define models which the daemon, running in the environment of your
Rails app under script/runner say, could put incoming information into
the db for the controllers to access.

Since you apparently want the daemon to respond in an appropriate way,
it would then be responsible for transporting the result of the http
request back to the requester via e-mail, sms, etc.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/