# loginGenerator - getting logged in username

**URL:** <https://www.ruby-forum.com/t/logingenerator-getting-logged-in-username/97132>\
**Category:** Rails\
**Created:** [July 5, 2006, 7:53am UTC](https://www.ruby-forum.com/t/logingenerator-getting-logged-in-username/97132 "2006-07-05T07:53:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [July 5, 2006, 7:53am UTC](https://www.ruby-forum.com/t/logingenerator-getting-logged-in-username/97132/1 "2006-07-05T07:53:21Z")

</div>

i am working on a site taht uses loginGenerator…

it’s a great little package, but i am running into one little problem…

i would like to have something that says:

"logged in as " in the site, but i am not quite getting it…

what i am using is:

You are logged in as: \<%= @session[:user] %\>

but i have tried:

You are logged in as: \<%= session[:user] %\>

anyone have any ideas?

also…

is there a way to get a list of all the current session variables?

in php, it would be something like:

print\_r($\_SESSION);

but i dunno how to do it in rails.

thanks!

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [July 5, 2006, 8:23am UTC](https://www.ruby-forum.com/t/logingenerator-getting-logged-in-username/97132/2 "2006-07-05T08:23:17Z")

</div>

On 7/5/06, sergio ruiz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> You are logged in as: \<%= session[:user] %\>

try session[:user].login, or whatever your username column is called.  
session[:user] contains the user object.

> is there a way to get a list of all the current session variables?
> 
> in php, it would be something like:
> 
> print\_r($\_SESSION);
> 
> but i dunno how to do it in rails.

p session or puts session.inspect if you want it dumped to the  
console, \<%= session.inspect %\> if you want it in a webpage.

martin

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [July 5, 2006, 8:29am UTC](https://www.ruby-forum.com/t/logingenerator-getting-logged-in-username/97132/3 "2006-07-05T08:29:09Z")

</div>

> p session or puts session.inspect if you want it dumped to the  
> console, \<%= session.inspect %\> if you want it in a webpage.

perfect!

thanks, martin…

for some reason, i still can’t access login…

i will keep at it…

thanks again…

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [July 5, 2006, 8:35am UTC](https://www.ruby-forum.com/t/logingenerator-getting-logged-in-username/97132/4 "2006-07-05T08:35:58Z")

</div>

On 7/5/06, sergio ruiz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> i will keep at it…
> 
> thanks again…

Can you post the schema of your user table?

martin

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [July 5, 2006, 8:41am UTC](https://www.ruby-forum.com/t/logingenerator-getting-logged-in-username/97132/5 "2006-07-05T08:41:48Z")

</div>

> Can you post the schema of your user table?
> 
> martin

yes:

CREATE TABLE `users` (  
`id` int(11) NOT NULL auto\_increment,  
`login` varchar(80) default NULL,  
`password` varchar(40) default NULL,  
PRIMARY KEY (`id`)  
) ENGINE=MyISAM DEFAULT CHARSET=utf8

i might also note that i tried:

You are logged in as: \<%= @session[:login] %\>

too…

thanks!

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [July 5, 2006, 10:12am UTC](https://www.ruby-forum.com/t/logingenerator-getting-logged-in-username/97132/6 "2006-07-05T10:12:02Z")

</div>

> \<%= @session[:user].login %\> should work fine

i don’t know why, but i also installed the LoginGenerator (and the ACL  
system) and for some unexplanitory reason, @session[‘user’] (as apposed  
to @session[:user]) worked for me.  
don’t know why, but i hope it helps.  
either way, the best way at it seems to do @session.inspect and see what  
name the username/login variable is listed under.

good luck,

harp

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [July 5, 2006, 9:15am UTC](https://www.ruby-forum.com/t/logingenerator-getting-logged-in-username/97132/7 "2006-07-05T09:15:29Z")

</div>

On 7/5/06, sergio ruiz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> `login` varchar(80) default NULL,  
> `password` varchar(40) default NULL,  
> PRIMARY KEY (`id`)  
> ) ENGINE=MyISAM DEFAULT CHARSET=utf8

\<%= @session[:user].login %\> should work fine, then, assuming that  
session[:user] itself is getting set correctly.

martin

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [July 5, 2006, 10:53am UTC](https://www.ruby-forum.com/t/logingenerator-getting-logged-in-username/97132/8 "2006-07-05T10:53:27Z")

</div>

@session[‘user’] is not the same as @session[:user] - it just happens  
that for many (but NOT all) of the Hash-like objects that Rails  
creates, they have been tweaked to not care if you’ve given a symbol  
or a string as the key (HashWithIndifferentAccess is the class of  
these critters).

Try this to prove it to yourself:

h = {} # new Hash  
h[‘a’] = ‘hello’  
h[:a] = ‘asta la vista, baby’  
puts h.inspect

For whatever reason, session is a regular Hash and not at  
HashWithIndifferentAccess, so you need to know the exact keys  
(including whether or not it was a String - ‘user’ - or a Symbol -  
:user). This might help in your views:

\<%= debug session %\>

James

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [July 5, 2006, 5:10pm UTC](https://www.ruby-forum.com/t/logingenerator-getting-logged-in-username/97132/9 "2006-07-05T17:10:08Z")

</div>

> \<%= debug session %\>

there is still something stumping me here…

i tried this, and got the stuff at the bottom of this post… which looks  
ok…

@session.inspect gives me the second set of output (on bottom of  
post)…

but @session[:login] still gives me nothing…

thanks for the help so far.

— !ruby/object:CGI::Session  
data: &id001  
user: !ruby/object:User  
attributes:  
id: “6”  
password: **passwordhere**  
login: sergio\_101  
return-to:  
flash: !map:ActionController::Flash::FlashHash {}

dbman: &id002 !ruby/object:CGI::Session::PStore  
hash: \*id001  
p: !ruby/object:PStore  
abort: false  
filename:  
/Users/sergioruiz/Sites/podCaster/public/…/config/…/tmp/sessions//ruby\_sess.6f80be42c9003bb7  
rdonly: false  
table:  
transaction: false  
dbprot:

- \*id002  
new\_session: false  
session\_id: 6c0a0bdeb66e7d6cf545e9649aaf0137

##“6”, “password”=\>“ **passwordhere** ”, “login”=\>“sergio\_101”}\>,  
“return-to”=\>nil, “flash”=\>{}}, @dbman=##“6”,  
“password”=\>“ **passwordhere** ”, “login”=\>“sergio\_101”}\>,  
“return-to”=\>nil, “flash”=\>{}}, @p=#\>, @new\_session=false,  
@session\_id=“6c0a0bdeb66e7d6cf545e9649aaf0137”, @dbprot=[##“6”,  
“password”=\>“ **passwordhere** ”, “login”=\>“sergio\_101”}\>,  
“return-to”=\>nil, “flash”=\>{}}, @p=#\>]\>
