# How to add after\_filter-style render

**URL:** <https://www.ruby-forum.com/t/how-to-add-after-filter-style-render/172079>\
**Category:** Rails\
**Created:** [July 14, 2009, 10:24am UTC](https://www.ruby-forum.com/t/how-to-add-after-filter-style-render/172079 "2009-07-14T10:24:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevo84](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f14d63/32.png) [@stevo84](https://www.ruby-forum.com/u/stevo84)\
**Post date:** [July 14, 2009, 10:24am UTC](https://www.ruby-forum.com/t/how-to-add-after-filter-style-render/172079/1 "2009-07-14T10:24:01Z")

</div>

Hello

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?

---

<div class="post-metadata">

**Author:** ![stevo84](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f14d63/32.png) [@stevo84](https://www.ruby-forum.com/u/stevo84)\
**Post date:** [July 14, 2009, 1:16pm UTC](https://www.ruby-forum.com/t/how-to-add-after-filter-style-render/172079/2 "2009-07-14T13:16:27Z")

</div>

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

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
