Servlet in RubyOnRails

Hi,

I want to develop a controller which acts like a servlet in java. That
means it doesn’t have any views associated with it, it just waits for
requests and treats those requests.
Though it’s not a web service because I don’t want to do RPC from a
client, I want to send an XML to it and then this controller will
treat the request.

How would you implement this?
Thanks :wink:

Ok, so I can do this for success:

return render(:nothing => true, :status => 200)

Thanks for your quick response :slight_smile:

On 6/7/07, [email protected] [email protected] wrote:

I want to develop a controller which acts like a servlet in java. That
means it doesn’t have any views associated with it, it just waits for
requests and treats those requests.
Though it’s not a web service because I don’t want to do RPC from a
client, I want to send an XML to it and then this controller will
treat the request.

At the very least you should at least be returning an HTTP header when
the request is processed. If you don’t want a view, thats easy. Just
make the actions in your controller look something like this:

def request_handler
# process the request here…
return render(:nothing => true, :status => status_from_processing)
end

Return a status that is appropriate to the result of whatever
processing you have done. If you aren’t familiar with them, you can
learn more about them here:

HTTP/1.1: Status Code Definitions

F. Morgan Whitney

Ok, so I can do this for success:

return render(:nothing => true, :status => 200)

Rather:

render(:nothing=>true, :status=>204)

204 indicates success and no content.

  • donald

There are many options. The controller can render the output directly
as either a string or an XML builder. You can directly render RJS
output using render :update.

You can also use a separate “view” file to render whatever output you
like and the controller just provides the raw data. Generally this is
the recommended approach. The view does not need to generate HTML for
a human. It can render XML for another program. The key idea is to
separate the data collection/navigation into the controller and let
the formatting/presentation of that be in a separate file called a
view. This allows returning the same data in multiple formats using
different views.

Michael

On Jun 7, 11:30 am, “[email protected][email protected]

Michael, I’m not sure I understood it all :slight_smile:
Can you point me to an example please?

Thanks