# Is it possible to render a modal dialog box from the server?

**URL:** <https://www.ruby-forum.com/t/is-it-possible-to-render-a-modal-dialog-box-from-the-server/165496>\
**Category:** Rails\
**Created:** [April 14, 2009, 3:35pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-render-a-modal-dialog-box-from-the-server/165496 "2009-04-14T15:35:04Z")\
**Posts on this page:** 5\
**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:** [April 14, 2009, 3:35pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-render-a-modal-dialog-box-from-the-server/165496/1 "2009-04-14T15:35:04Z")

</div>

I have a before filter that authorizes a user’s credentials before  
giving them access to any protected methods (pretty standard  
practice). If they fail authorization, I want to direct them to a  
chance to login or to create an account (also pretty standard  
practice).

Here’s the rub:  
I want to offer them a login form in a small modal box overlayed on  
their current screen. I know how to do this from the client side,  
using javascript, but in this case, I want the server to render that  
modal box (since it’s the server that determines that the user’s  
credentials are missing).

Any ideas how to do this?

Thanks,  
Yoram

---

<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:** [April 14, 2009, 4:47pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-render-a-modal-dialog-box-from-the-server/165496/2 "2009-04-14T16:47:55Z")

</div>

The server can only respond to client (browser) requests, so you have  
to either render a login page and then redirect to the original  
destination or you need to have some javascript to help with what you  
want. In short, the server can’t MAKE the browser do anything…

---

<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:** [April 14, 2009, 5:44pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-render-a-modal-dialog-box-from-the-server/165496/3 "2009-04-14T17:44:23Z")

</div>

so you have

> to either render a login page

yes but - can i render that login page as an overlay modal box instead  
of a full page? i suspect  
that the answer is not…

thanks for your reply

---

<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:** [April 14, 2009, 6:28pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-render-a-modal-dialog-box-from-the-server/165496/4 "2009-04-14T18:28:15Z")

</div>

yoram wrote:  
[…]

> yes but - can i render that login page as an overlay modal box instead  
> of a full page?  
> […]

Sure, with appropriate JavaScript and a suitably constructed partial or  
other HTML file. (But remember to make it accessible also to users who  
don’t have JavaScript turned on.)

Also see if HTTP-Basic authentication is suitable for your needs. With  
this model, the server tells the browser that it wants login  
credentials, and the browser presents a login dialog of some sort, so  
that the server doesn’t have to provide an HTML login form.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
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:** [April 16, 2009, 3:49pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-render-a-modal-dialog-box-from-the-server/165496/5 "2009-04-16T15:49:06Z")

</div>

On Tue, 2009-04-14 at 08:42 -0700, yoram wrote:

> yes but - can i render that login page as an overlay modal box instead  
> of a full page? i suspect  
> that the answer is not…

Check out Craig A.'s Redbox plugin.

HTH,  
Bill
