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.
6e0077ac498fb7ea7132e3c786b47e13?d=identicon&s=25 Andrew Kendall (Guest)
on 2005-12-26 09: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?
A6ebaaa00666e4f1934d9ca2c024aaf3?d=identicon&s=25 Rene Paulokat (Guest)
on 2005-12-26 12: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
1e1c7732f6f0850c915fc173e24330d2?d=identicon&s=25 MSK (Guest)
on 2006-04-27 13:19
That doesnt seem to work
F779209a7f02c754eda7b505898347f9?d=identicon&s=25 Rob Balfour (robtotheb)
on 2006-04-27 13: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.