# Getting the session variables after a redirect\_to

**URL:** <https://www.ruby-forum.com/t/getting-the-session-variables-after-a-redirect-to/109750>\
**Category:** Rails\
**Created:** [July 18, 2007, 4:53pm UTC](https://www.ruby-forum.com/t/getting-the-session-variables-after-a-redirect-to/109750 "2007-07-18T16:53:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mffreire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/90ced4/32.png) [@mffreire](https://www.ruby-forum.com/u/mffreire)\
**Post date:** [July 18, 2007, 4:53pm UTC](https://www.ruby-forum.com/t/getting-the-session-variables-after-a-redirect-to/109750/1 "2007-07-18T16:53:01Z")

</div>

Hi!

I set some session variables on a login\_controller and i want to access  
them after a redirect\_to (:controller =\> “auditor”, action =\> “check”).  
The problem is that the session variable are comming empty in the  
auditor view!!  
I tough that session variables last trought all controllers…iam wrong?  
Please tell me.

---

<div class="post-metadata">

**Author:** ![mffreire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/90ced4/32.png) [@mffreire](https://www.ruby-forum.com/u/mffreire)\
**Post date:** [July 18, 2007, 5:00pm UTC](https://www.ruby-forum.com/t/getting-the-session-variables-after-a-redirect-to/109750/2 "2007-07-18T17:00:17Z")

</div>

show the code that sets them, then show the code the gets them 🙂

---

<div class="post-metadata">

**Author:** ![mffreire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/90ced4/32.png) [@mffreire](https://www.ruby-forum.com/u/mffreire)\
**Post date:** [July 18, 2007, 5:05pm UTC](https://www.ruby-forum.com/t/getting-the-session-variables-after-a-redirect-to/109750/3 "2007-07-18T17:05:54Z")

</div>

Brian H. wrote:

> show the code that sets them, then show the code the gets them 🙂

\*\*\*\*\*\*\*\*\*\*\*\* login\_controller \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

def login  
#close\_session  
if request.post?  
obj = Cvsops.new  
output, status, error = obj.trylogin(params[:server],  
params[:name], params[:password])  
if status != 0  
flash.now[:notice] = “Error : #{error}”  
else  
session[:status] = status  
session[:name] = params[:name]  
session[:password] = params[:password]  
session[:server] = params[:server]  
redirect\_to(:controller =\> “auditor”, :action =\> “checkpre”)  
end  
end  
end

* * *

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* auditor controller \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

def checkpre  
# clean\_session  
if request.post?  
obj = Checker.new  
output, status, error = obj.check(params[:module],  
session[:server], session[:name], session[:password])  
info = obj.parseoutput(output)  
session[:module] = params[:module]  
session[:info] = info  
session[:status] = status  
session[:error] = error  
redirect\_to(:action =\> “check”)  
end  
end

* * *

Debuging the auditor controller i get the session[:server],  
session[:name] and session[:password] blank!

---

<div class="post-metadata">

**Author:** ![mffreire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/90ced4/32.png) [@mffreire](https://www.ruby-forum.com/u/mffreire)\
**Post date:** [July 18, 2007, 5:19pm UTC](https://www.ruby-forum.com/t/getting-the-session-variables-after-a-redirect-to/109750/4 "2007-07-18T17:19:44Z")

</div>

Marco Freire wrote:

> Brian H. wrote:
> 
> > show the code that sets them, then show the code the gets them 🙂
> 
> \*\*\*\*\*\*\*\*\*\*\*\* login\_controller \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> def login  
> #close\_session  
> if request.post?  
> obj = Cvsops.new  
> output, status, error = obj.trylogin(params[:server],  
> params[:name], params[:password])  
> if status != 0  
> flash.now[:notice] = “Error : #{error}”  
> else  
> session[:status] = status  
> session[:name] = params[:name]  
> session[:password] = params[:password]  
> session[:server] = params[:server]  
> redirect\_to(:controller =\> “auditor”, :action =\> “checkpre”)  
> end  
> end  
> end
> 
> * * *
> 
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* auditor controller \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> def checkpre  
> # clean\_session  
> if request.post?  
> obj = Checker.new  
> output, status, error = obj.check(params[:module],  
> session[:server], session[:name], session[:password])  
> info = obj.parseoutput(output)  
> session[:module] = params[:module]  
> session[:info] = info  
> session[:status] = status  
> session[:error] = error  
> redirect\_to(:action =\> “check”)  
> end  
> end
> 
> * * *
> 
> Debuging the auditor controller i get the session[:server],  
> session[:name] and session[:password] blank!

I forgot…the check action…

def check  
@info = session[:info]  
if session[:status] == 0  
flash.now[:notice] = “Compliance check created for module:  
#{session[:module]}”  
else  
flash.now[:notice] = session[:error]  
end  
end
