Michael Schuerig
2005-Aug-08 20:45 UTC
Redirection in superclass before filter: DoubleRenderError
In edit forms I''m providing buttons to move from the currently edited
object to the first, previous, next, last object in the list of
recently found objects. The actions are represented as an additional
request parameter, nav. In my controller superclass I have a method,
navigation_redirect (see bottom), that interprets this parameter and
redirects to the appropriate URL.
When I install a before filter in a concrete controller like this
prepend_before_filter :navigation_redirect
it works. When I push this filter to the superclass, I get a
DoubleRenderError, blamed on the redirect_to at the bottom of the
method. Frankly, I don''t understand what the difference is between
these two cases.
Michael
def navigation_redirect
current_id = params[:id].to_i
if (where = params[:nav]) && (navigation_list =
session[''navigation_list''])
redirect_to_id case where
when ''first''
navigation_list.first
when ''last''
navigation_list.last
when ''prev''
idx = navigation_list.index(current_id) || 1
navigation_list[idx - 1]
when ''next''
idx = navigation_list.index(current_id) || -1
idx = -1 if idx >= navigation_list.length - 1
navigation_list[idx + 1]
end
end
if redirect_to_id
redirect_to :id => redirect_to_id
end
end
--
Michael Schuerig Nothing is as brilliantly adaptive
mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org as selective
stupidity.
http://www.schuerig.de/michael/ --A.O. Rorty, The Deceptive Self
Aaron ''Jomdom'' Ransley
2005-Aug-08 22:48 UTC
RE: Redirection in superclass before filter: DoubleRenderError
Instead of:
prepend_before_filter :navigation_redirect
Try:
prepend_before_filter :navigation_redirect and return
The before_filter redirect doesn''t stop the rest of the action from
being
carried out, so you may end up calling redirect/render again somewhere in
the action, and that''s causing an error.
- Aaron ''Jomdom'' Ransley
- Web: www.jomdom.net
- Mail: jomdom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
-----Original Message-----
From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On
Behalf Of Michael Schuerig
Sent: Monday, August 08, 2005 1:45 PM
To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: [Rails] Redirection in superclass before filter: DoubleRenderError
In edit forms I''m providing buttons to move from the currently edited
object to the first, previous, next, last object in the list of
recently found objects. The actions are represented as an additional
request parameter, nav. In my controller superclass I have a method,
navigation_redirect (see bottom), that interprets this parameter and
redirects to the appropriate URL.
When I install a before filter in a concrete controller like this
prepend_before_filter :navigation_redirect
it works. When I push this filter to the superclass, I get a
DoubleRenderError, blamed on the redirect_to at the bottom of the
method. Frankly, I don''t understand what the difference is between
these two cases.
Michael
def navigation_redirect
current_id = params[:id].to_i
if (where = params[:nav]) && (navigation_list =
session[''navigation_list''])
redirect_to_id case where
when ''first''
navigation_list.first
when ''last''
navigation_list.last
when ''prev''
idx = navigation_list.index(current_id) || 1
navigation_list[idx - 1]
when ''next''
idx = navigation_list.index(current_id) || -1
idx = -1 if idx >= navigation_list.length - 1
navigation_list[idx + 1]
end
end
if redirect_to_id
redirect_to :id => redirect_to_id
end
end
--
Michael Schuerig Nothing is as brilliantly adaptive
mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org as selective
stupidity.
http://www.schuerig.de/michael/ --A.O. Rorty, The Deceptive Self
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
Michael Schuerig
2005-Aug-08 22:52 UTC
Re: Redirection in superclass before filter: DoubleRenderError
On Tuesday 09 August 2005 00:48, Aaron ''Jomdom'' Ransley wrote:> Instead of: > > prepend_before_filter :navigation_redirect > > Try: > > prepend_before_filter :navigation_redirect and return > > The before_filter redirect doesn''t stop the rest of the action from > being carried out, so you may end up calling redirect/render again > somewhere in the action, and that''s causing an error.No, that''s not the cause. Apparently I''ve misled you, though. I''m not calling prepend_before_filter from within a method, it''s at the top of the class definition. Michael -- Michael Schuerig Not only does lightning not strike mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org twice, it usually doesn''t strike once. http://www.schuerig.de/michael/ --Salman Rushdie, Fury
Aaron ''Jomdom'' Ransley
2005-Aug-08 22:58 UTC
RE: Re: Redirection in superclass before filter:DoubleRenderError
Did you give it a shot, none the less? I had a lot of such errors when I changed from 0.12 to 0.13, and doing the ''and return'' on the end of my filters helped in a lot of cases. - Aaron ''Jomdom'' Ransley - Web: www.jomdom.net - Mail: jomdom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Michael Schuerig Sent: Monday, August 08, 2005 3:53 PM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails] Re: Redirection in superclass before filter:DoubleRenderError On Tuesday 09 August 2005 00:48, Aaron ''Jomdom'' Ransley wrote:> Instead of: > > prepend_before_filter :navigation_redirect > > Try: > > prepend_before_filter :navigation_redirect and return > > The before_filter redirect doesn''t stop the rest of the action from > being carried out, so you may end up calling redirect/render again > somewhere in the action, and that''s causing an error.No, that''s not the cause. Apparently I''ve misled you, though. I''m not calling prepend_before_filter from within a method, it''s at the top of the class definition. Michael -- Michael Schuerig Not only does lightning not strike mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org twice, it usually doesn''t strike once. http://www.schuerig.de/michael/ --Salman Rushdie, Fury _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Michael Schuerig
2005-Aug-08 23:09 UTC
Re: Redirection in superclass before filter:DoubleRenderError
On Tuesday 09 August 2005 00:58, Aaron ''Jomdom'' Ransley wrote:> Did you give it a shot, none the less? I had a lot of such errors > when I changed from 0.12 to 0.13, and doing the ''and return'' on the > end of my filters helped in a lot of cases.Yes, I just did. The error must in some way be related to the class hierarchy. Remember, when I prepend the before filter in the concrete controller class it works. The error occurs only if I push the prepend the filter in my superclass. Michael -- Michael Schuerig I am the sum total of the parts mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org I control directly. http://www.schuerig.de/michael/ --Daniel C. Dennett, Elbow Room
Michael Schuerig
2005-Aug-09 11:39 UTC
Dev environment: inherited filters are executed multiple times (was: Redirection in superclass before filter:DoubleRenderError)
On Tuesday 09 August 2005 01:09, Michael Schuerig wrote:> On Tuesday 09 August 2005 00:58, Aaron ''Jomdom'' Ransley wrote: > > Did you give it a shot, none the less? I had a lot of such errors > > when I changed from 0.12 to 0.13, and doing the ''and return'' on the > > end of my filters helped in a lot of cases. > > Yes, I just did. The error must in some way be related to the class > hierarchy. Remember, when I prepend the before filter in the concrete > controller class it works. The error occurs only if I push the > prepend the filter in my superclass.I found the cause. When running in the development environment, filters defined in a superclass are executed for each class in the inheritance hierarchy downward. Reported as <http://dev.rubyonrails.org/ticket/1927> Michael -- Michael Schuerig Failures to use one''s frontal lobes mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org can result in the loss of them. http://www.schuerig.de/michael/ --William H. Calvin