How to add after_filter-style render


I would like to execute specific action rendering something into page after each of my ajax calls. In example I would like to update some div or display an alert.

How I imagine it could work is as follows

class ApplicationController < ActionController::Base   after_filter :do_something_after_each_ajax_call

  def do_something_after_each_ajax_call     if request.xml_http_request?       render :update do |page|         page << "alert('doing something!');       end     end   end end

Of course code above will yield with "Can only render or redirect once per action". How would You approach this problem?

This may seen kind of lame but works as far. If anyone knows better solution - share it please :slight_smile:

module ActionController   class Base     private

    def render_for_text_with_flashes(text = nil, status = nil, append_response = false) #:nodoc:       result = render_for_text_without_flashes(text, status, append_response)

      if response.content_type == Mime::JS         response.body << "$('messages').update('# {self.instance_variable_get("@template").message_block :flash_types => %w(back confirm error info warn notice), :on => MODEL_NAMES_FOR_MB}');new Effect.Highlight('messages'); "       end       result     end

    alias_method_chain :render_for_text, :flashes

  end end