Respond_to causes DoubleRenderError?

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

2006/4/7, Ryan N. [email protected]:

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,

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