# Redirecto\_to within helpers

**URL:** <https://www.ruby-forum.com/t/redirecto-to-within-helpers/126217>\
**Category:** Rails\
**Created:** [January 16, 2008, 12:37pm UTC](https://www.ruby-forum.com/t/redirecto-to-within-helpers/126217 "2008-01-16T12:37:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kabish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a88e57/32.png) [@kabish](https://www.ruby-forum.com/u/kabish)\
**Post date:** [January 16, 2008, 12:37pm UTC](https://www.ruby-forum.com/t/redirecto-to-within-helpers/126217/1 "2008-01-16T12:37:12Z")

</div>

Hi all,

In one of my helpers I would like to call a redirect\_to(url) action. I  
know the helpers are supposed almost only for formatting the view  
purposes but it’s the best way I have found to do what I want. If I call  
the redirect\_to action in a helper I get the error:

undefined method `redirect\_to’ for #\<#Class:0x23aaedc:0x23aaeb4\>

any solution for this?

Thanks,  
Alvaro.

---

<div class="post-metadata">

**Author:** ![kabish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a88e57/32.png) [@kabish](https://www.ruby-forum.com/u/kabish)\
**Post date:** [January 16, 2008, 2:29pm UTC](https://www.ruby-forum.com/t/redirecto-to-within-helpers/126217/2 "2008-01-16T14:29:29Z")

</div>

There are some hackish ways. Let’s start with the basics though:

What are you actually trying to do? Share that and someone can come up  
with  
the solution for you. If it’s a redirect, then it needs to be called  
from a  
controller. The best place to put that kinda stuff is the same place you  
put  
before\_filters: in the controller itself as a protected method, or in  
app/controllers/application.rb as a protected method if you want all  
controllers to see it.

(protected doesn’t _really_ make it protected in the Java sense, it just  
makes it so it’s not a URL action, as all public methods in controllers  
become actions, especially if you leave the default routes in).

-b

On Jan 16, 2008 5:37 AM, Alvaro P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![kabish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a88e57/32.png) [@kabish](https://www.ruby-forum.com/u/kabish)\
**Post date:** [January 16, 2008, 2:52pm UTC](https://www.ruby-forum.com/t/redirecto-to-within-helpers/126217/3 "2008-01-16T14:52:18Z")

</div>

Brian H. wrote:

> There are some hackish ways. Let’s start with the basics though:
> 
> What are you actually trying to do? Share that and someone can come up  
> with  
> the solution for you. If it’s a redirect, then it needs to be called  
> from a  
> controller. The best place to put that kinda stuff is the same place you  
> put  
> before\_filters: in the controller itself as a protected method, or in  
> app/controllers/application.rb as a protected method if you want all  
> controllers to see it.
> 
> (protected doesn’t _really_ make it protected in the Java sense, it just  
> makes it so it’s not a URL action, as all public methods in controllers  
> become actions, especially if you leave the default routes in).
> 
> -b
> 
> On Jan 16, 2008 5:37 AM, Alvaro P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Hi Brian,

yes I tried to call a redirect from within a helper, but after thinking  
twice I recognise that is a bad idea so I have rewritten the code to  
call it from the controller.

Thank you anyway for the response.

Alvaro.
