# Respond\_to causes DoubleRenderError?

**URL:** <https://www.ruby-forum.com/t/respond-to-causes-doublerendererror/57228>\
**Category:** Rails\
**Created:** [April 8, 2006, 5:03am UTC](https://www.ruby-forum.com/t/respond-to-causes-doublerendererror/57228 "2006-04-08T05:03:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ea5d25/32.png) [@ryana](https://www.ruby-forum.com/u/ryana)\
**Post date:** [April 8, 2006, 5:03am UTC](https://www.ruby-forum.com/t/respond-to-causes-doublerendererror/57228/1 "2006-04-08T05:03:06Z")

</div>

I have a custom authentication plugin that redirects users to a login  
site if they aren’t already authenticated and their session hasn’t  
timed out. I had things working fine with straight http requests, but  
wanted to add support for ajax requests. I thought this would be a  
simple matter of replacing all of my “redirect\_to and return  
false” calls with something like “redirect and return false”,  
where the redirect method wraps a respond\_to block. For example:

```
def redirect(url)
  respond_to do |wants|
    wants.html { redirect_to url }
    wants.js { render :update do |page| page.redirect_to url end }
  end
end

```

However, this causes a DRE when I deployed it on my FCGI production  
server. In fact, removing the wants.js line so that the function is  
just

```
def redirect(url)
  respond_to do |wants|
    wants.html { redirect_to url }
  end
end

```

still triggers a DRE. The only time things work as expected are when  
the function reads:

```
def redirect(url)
    redirect_to url
end

```

It seems that the respond\_to method is breaking my login plugin. I’m a  
little confused as to why this would hapen, though. Has anyone seen  
this behavior before?

–  
Ryan

---

<div class="post-metadata">

**Author:** ![ryana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ea5d25/32.png) [@ryana](https://www.ruby-forum.com/u/ryana)\
**Post date:** [April 8, 2006, 8:43am UTC](https://www.ruby-forum.com/t/respond-to-causes-doublerendererror/57228/2 "2006-04-08T08:43:57Z")

</div>

2006/4/7, Ryan N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> ```
> def redirect(url)
> respond_to do |wants|
> wants.html { redirect_to url }
> wants.js { render :update do |page| page.redirect_to url end }
> end
> end
> 
> ```

Are you sure you are not doing any render work in the CALLERs of  
redirect ?

Check the stacktrace to see where the second render occurs.

Hope that helps,

---

<div class="post-metadata">

**Author:** ![ryana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ea5d25/32.png) [@ryana](https://www.ruby-forum.com/u/ryana)\
**Post date:** [April 8, 2006, 10:20am UTC](https://www.ruby-forum.com/t/respond-to-causes-doublerendererror/57228/3 "2006-04-08T10:20:56Z")

</div>

Nope, there are absolutely no calls to render or redirect\_to on the  
stack. I wish there were, that’s the first thing I checked! Here is  
the backtrace:

ActionController::DoubleRenderError:  
`redirect_to'`redirect’  
`respond'`respond’  
`respond_to'`redirect’  
`validate_user_identity'`call\_filters’  
`call_filters'`before\_action’  
`perform_action_without_benchmark'`perform\_action\_without\_rescue’  
`measure'`perform\_action\_without\_rescue’  
`perform_action'`process\_without\_filters’  
`process_without_session_management_support'`process’  
`dispatch'`process\_request’  
`process!'`each\_cgi’  
`each_cgi'`process!’  
`process!’  
dispatch.fcgi:24

You can see my plugin’s calls to ‘validate\_user\_identity’ and  
‘redirect’ on the stack, but no calls to ‘redirect\_to’ or ‘render’.  
Basically, stuff works when I don’t have a respond\_to but breaks when  
I do have a redirect\_to. This is on 1.1.1, fwiw.

–  
Ryan
