I’ve got AAA loaded and working. I now want to put a smarter login form
on the sidebar of my site.
If the user is not logged in, I’d like to display a typical form in the
sidebar that collects the user ID/password and allows the user to login.
If the user is logged in, the box should display something like ‘Logged
in user: FirstName Lastname’ and a button to allow the user to log out.
I’m new at rails, so I’m confused about how to go about doing this.
The main site template is in app/views/layouts/application.rb, and I’ve
tried modifying it as:
<% if [ logged in ] %>
<%= render(:partial => ‘account/logout’ %>
<% else %>
<%= render(:partial => ‘account/login’ %>
<% end %>
With all sorts of unsuccessful guesses for the [ logged in ] portion. I
can’t figure out how to tell if anyone is logged in without the page
throwing exceptions. Is there any way to have the view dump out all
available instance variables, or at least a list of them?
Also, it’s not DRY, as the login form is actually already located in
app/views/account/login.rhtml. In order to use the partials, I have to
copy the form to app/views/account/_login.rhtml.
Ideally, it would be great if I could just have one line of code in the
main view like
<%= render_the_login_form %> and the code would be smart enough to show
the proper form based on the logged in state of the user.
I get the feeling that I’m not going about this in a very rails-like
Advice appreciated. Thanks!