# Servlet in RubyOnRails

**URL:** <https://www.ruby-forum.com/t/servlet-in-rubyonrails/106246>\
**Category:** Rails\
**Created:** [June 7, 2007, 8:31pm UTC](https://www.ruby-forum.com/t/servlet-in-rubyonrails/106246 "2007-06-07T20:31:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 7, 2007, 8:31pm UTC](https://www.ruby-forum.com/t/servlet-in-rubyonrails/106246/1 "2007-06-07T20:31:17Z")

</div>

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 😉

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 7, 2007, 9:04pm UTC](https://www.ruby-forum.com/t/servlet-in-rubyonrails/106246/2 "2007-06-07T21:04:21Z")

</div>

Ok, so I can do this for success:

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

Thanks for your quick response 🙂

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 7, 2007, 8:45pm UTC](https://www.ruby-forum.com/t/servlet-in-rubyonrails/106246/3 "2007-06-07T20:45:18Z")

</div>

On 6/7/07, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)

F. Morgan Whitney

> **[Home - Blizzo](http://www.blizzo.com)**
>
> Insight. Culture. Passion. OUR STORY About Our Clients We recognize that our clients are the key element in our success and that we play an important part in helping build their business and brand. Whether our client is a small service business or a...

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 7, 2007, 9:21pm UTC](https://www.ruby-forum.com/t/servlet-in-rubyonrails/106246/4 "2007-06-07T21:21:23Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 7, 2007, 9:24pm UTC](https://www.ruby-forum.com/t/servlet-in-rubyonrails/106246/5 "2007-06-07T21:24:24Z")

</div>

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, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 7, 2007, 9:52pm UTC](https://www.ruby-forum.com/t/servlet-in-rubyonrails/106246/6 "2007-06-07T21:52:30Z")

</div>

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

Thanks
