views:

174

answers:

3

I have a User model that contains information such as username, email, hometown, etc. When the user is logged in, he can edit any of his information via the show page (/users/723, for example).

I'd like to have a "public" version of this page that can be viewed by someone that's not logged in or by someone that's logged in as someone else. It would have varying levels of information about the user and not have any of the links to edit information.

What's the cleanest way to properly show the three different versions of this page?

Addendum.

I am currently using authlogic for authentication and acl9 for access control. However, I don't see this as a question of authentication and authorization. I think it's a question of controller/view design. Whether the user is logged in or owns the information is incidental. If you wanted to display Widgets in three different manners based on some session state, I would think you'd be able to use the answer to this question.

+1  A: 

There are tons of ways of doing this, and I do not think there is a cleanest way.

I would probably break the page into partials, one partial for each grouping of information you need.

Then you could have variables control which partials get rendered.

For example (in HAML):

- if @admin
  render :partial => 'admin_panel'

For the real simple stuff you could inline the if (and not have a partial)

Alternatively, if stuff is getting out of hand, you can have different views for each "show" page.

Sam Saffron
I agree with Sam on this one, with the slight caveat that depending on the differences, it may make more sense to just make the changes inline. For example, on a site where I just want to enable quick-edit functionality for admins, that's a simple condition inside the view, but I don't want to punt out to partials when the differences will be so minor.
scottru
A: 

For User Profiles (As well as user authentication), I highly recommend looking at Authlogic. It makes everything extremely simple, and is very well designed. You basically add a before filter that says:

before_filter :require_login, :only => [:edit, :update]

Then you must be logged in to go to edit (and thus post to update), otherwise it is publicly viewable.

You can download an example application from here.

It also supports integration with OpenID, LDAP, Facebook Connect, and OAuth (Twitter) via some addons, which are discussed on the github page for the project (linked above).

I hope my answer was helpful.

Mike Trpcic
@Mike, I think the OP already has some way to do authentication and authorization, he is just looking for a way to cleanly break down his view.
Sam Saffron
@Sam, I understand, but Authlogic is literally a "drop-in-and-go" solution that contains the functionality he is looking for without any hassle. It was just a suggestion which he may not have found, and I thought it merited a mention.
Mike Trpcic
A: 

I think you should create a second controller (e.g. memberprofiles controller). So you can split up the user-edit area from the public access area.

Lichtamberg