Filter to execute before render but after controller?

I believe rendering starts when render is called, and there's no default way to defer it. Here's one thing you could do:

filters are applied in the same order declared. So make a second after-filter that calls render with an array args stored in a class variable. Then anywhere you would normally call render, set the variable.


There are also some gems to achieve this. One of them is rails3_before_render. It works similarly to filters, for example:

class PostsController < ApplicationController
  before_render :ping, :except => [:destroy]

  def index; end
  def new; end
  def show; end
  def destroy; end                                                                          

  private
    def ping
      Rails.logger.info "Ping-Pong actions"
    end
end

(code snipped copied from gem documentation)


I had the same problem and solved it like this:

class ApplicationController < ActionController::Base
  def render *args
    add_breadcrumbs
    super
  end
end