Forum: Ruby on Rails respond_to causes DoubleRenderError?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ryan N. (Guest)
on 2006-04-08 07:03
(Received via mailing list)
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 <blah> and return
false" calls with something like "redirect <blah> 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
François B. (Guest)
on 2006-04-08 10:43
(Received via mailing list)
2006/4/7, Ryan N. <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,
Ryan N. (Guest)
on 2006-04-08 12:20
(Received via mailing list)
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
This topic is locked and can not be replied to.