Newbie: Login/Logout in view


#1

I am using the acts_as_authenticated plugin to manage logging in/logging
out. There are a few controllers, such as search, that I don’t mind
people accessing regardless of whether they are logged in or logged out.

My current view just has some static links on the left that say Login
and Logout. How should I set it up so that it says Login when not logged
in and log out when logged in? Is there code that would go in the view
to detect iflogged in and display the appropriate link? If so, what
would that look like?

I guess the alternative is to have two identical controllers, but that
doesn’t seem like a good solution.

Thanks in advance…


#2

Vince W. wrote:

I am using the acts_as_authenticated plugin to manage logging in/logging
out. There are a few controllers, such as search, that I don’t mind
people accessing regardless of whether they are logged in or logged out.

My current view just has some static links on the left that say Login
and Logout. How should I set it up so that it says Login when not logged
in and log out when logged in? Is there code that would go in the view
to detect iflogged in and display the appropriate link? If so, what
would that look like?

I guess the alternative is to have two identical controllers, but that
doesn’t seem like a good solution.

Thanks in advance…

<% if current_user %>
<%= link_to ‘Logout’, :controller => ‘account’, :action => ‘logout’ %>
<% else %>
<%= link_to ‘Login’, :controller => ‘account’, :action => ‘login’ %>
<% end %>