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 <username>" in the site, but i am not quite getting it.. what i am using is: <p>You are logged in as: <%= @session[:user] %> but i have tried: <p>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! -- Posted via http://www.ruby-forum.com/.
On 7/5/06, sergio ruiz <sergio@village-buzz.com> wrote:> > <p>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
> 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.. -- Posted via http://www.ruby-forum.com/.
Martin DeMello
2006-Jul-05 06:34 UTC
[Rails] Re: loginGenerator - getting logged in username
On 7/5/06, sergio ruiz <sergio@village-buzz.com> wrote:> > > 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..Can you post the schema of your user table? martin
sergio ruiz
2006-Jul-05 06:42 UTC
[Rails] Re: Re: loginGenerator - getting logged in username
> > Can you post the schema of your user table? > > martinyes: 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: <p>You are logged in as: <%= @session[:login] %> too.. thanks! -- Posted via http://www.ruby-forum.com/.
Martin DeMello
2006-Jul-05 07:12 UTC
[Rails] Re: Re: loginGenerator - getting logged in username
On 7/5/06, sergio ruiz <sergio@village-buzz.com> wrote:> > > > > 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<%= @session[:user].login %> should work fine, then, assuming that session[:user] itself is getting set correctly. martin
harper
2006-Jul-05 08:12 UTC
[Rails] Re: Re: Re: loginGenerator - getting logged in username
> <%= @session[:user].login %> should work finei 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 -- Posted via http://www.ruby-forum.com/.
James Adam
2006-Jul-05 08:50 UTC
[Rails] Re: Re: Re: loginGenerator - getting logged in username
@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 On 7/5/06, harper <harper@chalice.ci> wrote:> > > <%= @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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- * J * ~
sergio ruiz
2006-Jul-05 15:10 UTC
[Rails] Re: Re: Re: Re: loginGenerator - getting logged in username
> > <%= 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=#>]> -- Posted via http://www.ruby-forum.com/.