Forum: Ruby on Rails Display Login Status

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Andrew Kendall (Guest)
on 2005-12-26 10:21
I'm using salted login generator and would like my pages to display a
login status bar.

If the user is logged in I want it to show something like:

---------------------------------------------------------------
You are currently logged in as UserX (Logout)
---------------------------------------------------------------

And if they're not logged in:

---------------------------------------------------------------
Login/Signup
---------------------------------------------------------------


Any ideas?
Rene P. (Guest)
on 2005-12-26 13:48
(Received via mailing list)
On Mon, Dec 26, 2005 at 09:21:21AM +0100, Andrew Kendall wrote:
>
> ---------------------------------------------------------------
> Login/Signup
> ---------------------------------------------------------------
>
>
> Any ideas?

after user authenticated store 'User' in the session -
on the template it could go like:

<%= link_to_unless( @session[:user].nil?, 'logout', {
	:controller => 'foo', :action => 'logout' } %>
<%= link_to_unless( @session[:user], 'login', {
	:controller => 'foo', :action => 'login' } %>

or if u prefer more lines:

<% if @session[:user] %>
	currently logged in as <%= @session[:user].login %>
	<%= link_to 'logout', :action => 'logout' %>
<% else %>
	not logged in	<%= link_to 'login', :action => 'login' %>
<% end %>

but i guess u would have found out yourself...

regards
rene
MSK (Guest)
on 2006-04-27 15:19
That doesnt seem to work
Rob B. (Guest)
on 2006-04-27 15:45
MSK wrote:
> That doesnt seem to work

Try:

<% if @session['user'] %>
	currently logged in as <%= @session['user'].login %>
	<%= link_to 'logout', :action => 'logout' %>
<% else %>
	not logged in	<%= link_to 'login', :action => 'login' %>
<% end %>


Worked for me with salted
This topic is locked and can not be replied to.