# Rendering in after\_filter

**URL:** <https://www.ruby-forum.com/t/rendering-in-after-filter/60266>\
**Category:** Rails\
**Created:** [May 11, 2006, 7:15pm UTC](https://www.ruby-forum.com/t/rendering-in-after-filter/60266 "2006-05-11T19:15:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Esad\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3da27b/32.png) [@Esad\_H](https://www.ruby-forum.com/u/Esad_H)\
**Post date:** [May 11, 2006, 7:15pm UTC](https://www.ruby-forum.com/t/rendering-in-after-filter/60266/1 "2006-05-11T19:15:50Z")

</div>

Hi!

Is it possible to render the action within the after\_filter method, or  
is the rendering performed before?

I have something like this:

class FooController  
after\_filter :send  
def a  
@content=…  
end

def b  
@content=…  
end  
protected  
def send  
send\_data(@content,…)  
end  
end

However, when calling the action a or b, the @content doesn’t get sent,  
but instead rails shows an error message abour missing template.

---

<div class="post-metadata">

**Author:** ![Esad\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3da27b/32.png) [@Esad\_H](https://www.ruby-forum.com/u/Esad_H)\
**Post date:** [May 12, 2006, 5:55pm UTC](https://www.ruby-forum.com/t/rendering-in-after-filter/60266/2 "2006-05-12T17:55:33Z")

</div>

Hi,

On May 11, 2006, at 1:15 PM, Esad H. wrote:

> ```
> @content=...
> 
> ```
> 
> However, when calling the action a or b, the @content doesn’t get  
> sent,  
> but instead rails shows an error message abour missing template.

Here’s a bit of guessing…

The response body already has the content by the time the filter is  
run, well, it does by the time the around filters are run so I assume  
the after filters too. So I’d guess that rails is looking for its  
response content before the filters are run – this makes sense since  
the after filters are supposed to have access to whatever is being  
returned. Try adding a ‘return false’ at the end of the a and b  
methods – if that doesn’t stop the template error then something  
else is wrong. The send\_data may still not work from the filter, if  
it doesn’t, try writing “response.body = @content” (and you’ll have  
to get the headers setup properly as well). (note that if you are  
using around filters the controller is the argument and you write  
something like: “controller.response.body = controller.content” so  
make sure that the @content attribute is visible).

Cheers,  
Bob

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

* * *

Bob H. – blogs at \<[http://www.recursive.ca/](http://www.recursive.ca/)  
hutch/\>  
Recursive Design Inc. – [http://www.recursive.ca/](http://www.recursive.ca/)  
Raconteur – [http://www.raconteur.info/](http://www.raconteur.info/)  
xampl for Ruby – [http://rubyforge.org/projects/xampl/](http://rubyforge.org/projects/xampl/)
