Many apps use app/views/layouts/application.html.erb as a layout that
applies to the website globally. If you do want separate layouts for
your two controllers, I would create a logout partial. You could do
it by making a file app/views/shared/_logout.html.erb that contains
your logout link. Then from your two other layouts you would have to
do: <%= render :partial => "shared/logout" %>
Regarding the controller, you would need to put the suggested
before_filter in the application.rb controller so that it runs for any
controller. I would expand the logic a little bit. Probably something
like this:
class ApplicationController
before_filter :find_current_user
def find_current_user
@current_user = User.find(session[:user_id]) if session[:user_id]
end
def logged_in?
!session[:user_id].nil?
end
helper_method :logged_in?
end
Then in your partial:
<% if logged_in? %>
<%= link_to "log out #{@current_user.name}", logout_path
<% end %>
For logout_path to be available, you'll need to be using named routes.
If you're not comfortable doing that in Rails yet, you could
use :controller => 'admin', :action => 'logout' like you originally
had.