DRY approach to views for password protected parts of a site

Hello,

I’m working on a system that has a protected part. Users have to login
in
order to be able to go there.
Now I was wondering how I should handle the layout in a DRY way. All
pages
have the same layout with a header that contains either a few options
and a
login part or the full stack of options.
How should I code that layout in order to have a nice DRY layout? I want
to
avoid to do checks on being authenticated in every layout. I prefer to
have
a single template (with a fixed header and footer) for the entire site
that
would be “automagically” included and rendered for users that are
authenticated and not authenticated at once. I guess this is a quite
normal
question but I can’t find an article that also discusses the layout
organisation (ie which file should I place where).

Bart

I prefer to have a single template (with a fixed header and footer) for the
entire site that would be “automagically” included and rendered for users that
are authenticated and not authenticated at once.

I created a helper method (actually a controller method that I made
available as a helper too) called logged_in? in my application
controller, so I can do stuff like this in my layouts/views:

<%= render(:partial => ‘user/user_dashboard’) if logged_in? %>

Pertinent parts from the application controller:

class ApplicationController < ActionController::Base
helper_method :logged_in?

def logged_in?
session[:user_id].nil? ? false : true
end

end