# Redirect\_to from initialize method

**URL:** <https://www.ruby-forum.com/t/redirect-to-from-initialize-method/98508>\
**Category:** Rails\
**Created:** [July 15, 2006, 5:31am UTC](https://www.ruby-forum.com/t/redirect-to-from-initialize-method/98508 "2006-07-15T05:31:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![orz42](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/45deac/32.png) [@orz42](https://www.ruby-forum.com/u/orz42)\
**Post date:** [July 15, 2006, 5:31am UTC](https://www.ruby-forum.com/t/redirect-to-from-initialize-method/98508/1 "2006-07-15T05:31:38Z")

</div>

Hello, I’m curious as to why this bit of code doesn’t work:

–  
class SignupController \< ApplicationController

def initialize  
signup.call  
end

def signup  
redirect\_to :action =\> “signup\_form”  
end

end

–

You have a nil object when you didn’t expect it!  
The error occured while evaluating nil.rewrite

–

Whereas if I comment the signup.call and call the signup method directly  
the redirection works fine. My apologies if this is utterly trivial,  
thanks.

---

<div class="post-metadata">

**Author:** ![orz42](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/45deac/32.png) [@orz42](https://www.ruby-forum.com/u/orz42)\
**Post date:** [July 15, 2006, 5:41pm UTC](https://www.ruby-forum.com/t/redirect-to-from-initialize-method/98508/2 "2006-07-15T17:41:55Z")

</div>

I;m new in towm myself, but I think initialize is when the instance  
itself initializes, not when the framework wants it to do something.  
ActionController handles GETs and POSTs from the users, and with no  
actions defined, I think it infers the action (and page) “index”.

Therefor:

def index  
redirect\_to :action =\> “signup\_form”  
end

might be more appropriate (assuming you have def signup\_form somewhere  
in this controller).

Cheers

Alexandre H. wrote:

> Hello, I’m curious as to why this bit of code doesn’t work:  
> class SignupController \< ApplicationController
> 
> def initialize  
> signup.call  
> end
> 
> def signup  
> redirect\_to :action =\> “signup\_form”  
> end
> 
> end
> 
> –
> 
> You have a nil object when you didn’t expect it!  
> The error occured while evaluating nil.rewrite
