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!
On 7/5/06, sergio ruiz [email protected] 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
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…
On 7/5/06, sergio ruiz [email protected] wrote:
i will keep at it…
thanks again…
Can you post the schema of your user table?
martin
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!
<%= @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
On 7/5/06, sergio ruiz [email protected] 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
@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
<%= 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=#>]>