# Rails equivalent to J2EE getRequestDispatcher().forward(...)

**URL:** <https://www.ruby-forum.com/t/rails-equivalent-to-j2ee-getrequestdispatcher-forward/79098>\
**Category:** Rails\
**Created:** [December 12, 2006, 3:51am UTC](https://www.ruby-forum.com/t/rails-equivalent-to-j2ee-getrequestdispatcher-forward/79098 "2006-12-12T03:51:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maurice\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@Maurice\_Y](https://www.ruby-forum.com/u/Maurice_Y)\
**Post date:** [December 12, 2006, 3:51am UTC](https://www.ruby-forum.com/t/rails-equivalent-to-j2ee-getrequestdispatcher-forward/79098/1 "2006-12-12T03:51:06Z")

</div>

Hello Rails community

Is there a Rails equivalent to the J2EE  
getRequestDispatcher().forward(…) or  
the getRequestDispatch().include(…), or,  
say, the PHP @readfile(…) ?

In particular, what I would like to do is first authenticate  
for permission, and if permitted, serve static content.  
The J2EE forward and include mechanisms allow content  
to be served without the service URL showing up in the  
URL bar in the client browser. This means that the original  
request can contain necessary static content location  
information, but after permission is ascertained, the full  
path to the content is assembled and passed only internally  
within the server.

Maurice Y.

---

<div class="post-metadata">

**Author:** ![Maurice\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@Maurice\_Y](https://www.ruby-forum.com/u/Maurice_Y)\
**Post date:** [December 12, 2006, 5:32am UTC](https://www.ruby-forum.com/t/rails-equivalent-to-j2ee-getrequestdispatcher-forward/79098/2 "2006-12-12T05:32:43Z")

</div>

I think u r asking about redirect\_to

Maurice Y. wrote:

> Hello Rails community
> 
> Is there a Rails equivalent to the J2EE  
> getRequestDispatcher().forward(…) or  
> the getRequestDispatch().include(…), or,  
> say, the PHP @readfile(…) ?
> 
> In particular, what I would like to do is first authenticate  
> for permission, and if permitted, serve static content.  
> The J2EE forward and include mechanisms allow content  
> to be served without the service URL showing up in the  
> URL bar in the client browser. This means that the original  
> request can contain necessary static content location  
> information, but after permission is ascertained, the full  
> path to the content is assembled and passed only internally  
> within the server.
> 
> Maurice Y.

---

<div class="post-metadata">

**Author:** ![Maurice\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@Maurice\_Y](https://www.ruby-forum.com/u/Maurice_Y)\
**Post date:** [December 12, 2006, 5:39am UTC](https://www.ruby-forum.com/t/rails-equivalent-to-j2ee-getrequestdispatcher-forward/79098/3 "2006-12-12T05:39:16Z")

</div>

It sounds like you want to do a reverse proxy. I do recall someone on  
the Rails wiki posting some code to do that. However I’d be hesitant to  
do it for real unless you had just a few things you wanted to  
protect/expose.

If your Rails app is the main application and you just want to expose  
some back end static content for authenticated users then the wiki  
solution should work fine. Any more than that then I’d recommend  
investigating a real reverse proxy solution and have your apps and  
content sit behind that and let it take care of authentication.

Cheers,  
John

---

<div class="post-metadata">

**Author:** ![Maurice\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@Maurice\_Y](https://www.ruby-forum.com/u/Maurice_Y)\
**Post date:** [December 12, 2006, 6:47am UTC](https://www.ruby-forum.com/t/rails-equivalent-to-j2ee-getrequestdispatcher-forward/79098/4 "2006-12-12T06:47:24Z")

</div>

After seeing the other replies I realize that I misunderstood what you  
were saying. The talk of URLs made me think the static content was on a  
different web server. But I think you mean you have static content  
outside the document root that you want to serve to clients that you  
first authenticate via your rails app. That’s easier. 🙂

Try send\_file,

> **[ActionController::Streaming](https://api.rubyonrails.org/classes/ActionController/Streaming.html#M000072)**
>
> Allows views to be streamed back to the client as they are rendered. By default, Rails renders views by first rendering the template and then the layout.

---

<div class="post-metadata">

**Author:** ![Maurice\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@Maurice\_Y](https://www.ruby-forum.com/u/Maurice_Y)\
**Post date:** [December 13, 2006, 2:41am UTC](https://www.ruby-forum.com/t/rails-equivalent-to-j2ee-getrequestdispatcher-forward/79098/5 "2006-12-13T02:41:25Z")

</div>

Selvaraj

Thanks for your response…

Maurice

---

<div class="post-metadata">

**Author:** ![Maurice\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@Maurice\_Y](https://www.ruby-forum.com/u/Maurice_Y)\
**Post date:** [December 12, 2006, 6:03am UTC](https://www.ruby-forum.com/t/rails-equivalent-to-j2ee-getrequestdispatcher-forward/79098/6 "2006-12-12T06:03:17Z")

</div>

On 12/11/06, Maurice Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The J2EE forward and include mechanisms allow content  
> to be served without the service URL showing up in the  
> URL bar in the client browser. This means that the original  
> request can contain necessary static content location  
> information, but after permission is ascertained, the full  
> path to the content is assembled and passed only internally  
> within the server.
> 
> Maurice Y.

A pretty close equivalent of this would be render\_component, but  
components add significant overhead and are slated to be deprecated.

## – Kent

> **[DATANOISE.COM](https://www.datanoise.com)**
>
> DATANOISE.COM - Contact us for any business inquiries
