How to overcome the DoubleRender problem?

This should not create a problem at all as I do it all the time. My guess is that you are assuming that render and redirect_to immediately return from a method, but they don't. All redirect_to does is add a 302 header to the response object that is sent back to the browser. Without seeing your code, all I can do is assume, but try changing the redirect_to line to something like the following (notice the && return):

redirect_to(:controller => 'foo', :action => 'bar') && return

-Bill

Joshua Muheim wrote:

While this is perfectly valid syntax, I would recommend:

  redirect_to(...)
  return

because it is more clear what is going on. The && trick works --
unless redirect_to suddenly starts returning true.

--Michael

Actually the return will happen as long as the redirect_to returns
anything but nil or false.

Gah, brain fart. :slight_smile:

The point is, && is "short-circuit" in that the first in the path that
fails causes the rest to not even run.

--Michael

You can also try out:

return redirect_to(...)

You can avoid the "short-circuit".

- Herry

which calls the method member_requests():

  def member_requests(right_name, obj, options = {}, &block)
    if
logged_in_member.has_system_right?(SystemRight.find_by_model_class_and_name(obj.to_s,
right_name))
      yield if block_given?
    else
      render :file => "#{RAILS_ROOT}/public/404.html", :layout => true,
:status => 404
    end
  end

And that's where the DoubleRenderError is thrown! Anyone can see where
the problem is? I just want to render the 404.html file, nothing else...
No double rendering or stuff! :stuck_out_tongue:

As far as I can see you then trickle down to

model_obj.new_record? ?
      render(:action => :new) :
      render(:action => :edit)

Which renders a second time, hence the error. I can also see quite a few other paths by which this could happen.

Fred

that there are other cases. eg member_requests rendering and you later redirecting.

It's dead simple. If you've called render or redirect_to once in an
action, make sure you don't do either of them again.