Forum: Ruby on Rails newbie: Login/Logout in view

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.
Vince W. (Guest)
on 2006-05-08 19:21
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..
Alex W. (Guest)
on 2006-05-08 21:12
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 %>
This topic is locked and can not be replied to.