# Special case rendering from filter

**URL:** <https://www.ruby-forum.com/t/special-case-rendering-from-filter/165075>\
**Category:** Rails\
**Created:** [April 8, 2009, 8:59pm UTC](https://www.ruby-forum.com/t/special-case-rendering-from-filter/165075 "2009-04-08T20:59:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zaczheng](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/edb3f5/32.png) [@zaczheng](https://www.ruby-forum.com/u/zaczheng)\
**Post date:** [April 8, 2009, 8:59pm UTC](https://www.ruby-forum.com/t/special-case-rendering-from-filter/165075/1 "2009-04-08T20:59:06Z")

</div>

I have a special case(does not normally occur) render in a filter.  
Because its in a filter, I can’t end execution with a ‘return’ which  
would work otherwise. Therefore I get this error:

Can only render or redirect once per action

My code in gist:

class MyController \< ApplicationController  
before\_filter :authenticate

def priviledged\_action  
redirect\_to :action =\> “vip\_room”  
end

protected  
def authenticate  
if params[:password] != “pass”  
render :status =\> 403, :text =\> “Access denied”  
# Things I have tried to end execution here:  
# ‘return’ does end execution as simply returns filter  
# ‘exit’ causes crash  
# I can’t think of a way to use catch/throw  
end  
end  
end

Can anyone please advise?

---

<div class="post-metadata">

**Author:** ![zaczheng](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/edb3f5/32.png) [@zaczheng](https://www.ruby-forum.com/u/zaczheng)\
**Post date:** [April 9, 2009, 12:58am UTC](https://www.ruby-forum.com/t/special-case-rendering-from-filter/165075/2 "2009-04-09T00:58:25Z")

</div>

On Apr 8, 7:59 pm, Zac Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have a special case(does not normally occur) render in a filter.  
> Because its in a filter, I can’t end execution with a ‘return’ which  
> would work otherwise. Therefore I get this error:
> 
> Can only render or redirect once per action

what version of rails are you using ? In rails 2 and above rendering  
from a filter should cause the filter chain to halt. in previous  
versions you had to return false from your filter.

Fred

---

<div class="post-metadata">

**Author:** ![zaczheng](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/edb3f5/32.png) [@zaczheng](https://www.ruby-forum.com/u/zaczheng)\
**Post date:** [April 10, 2009, 4:00pm UTC](https://www.ruby-forum.com/t/special-case-rendering-from-filter/165075/3 "2009-04-10T16:00:10Z")

</div>

Frederick C. wrote:

> what version of rails are you using ? In rails 2 and above rendering  
> from a filter should cause the filter chain to halt. in previous  
> versions you had to return false from your filter.

You’re right! My semi pseudocode oversimplified my actual code. There’s  
a logic that prevents false being returned from the filter.

Thanks mate
