Redirect_to from initialize method

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.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs