Different views for different conditions

Hi Guys

I have the following questions:

Create the User Hub Page, which would be accessible as index action of
the User controller. Yes, you have already something in this action: if
you made the Week 4 Activity well, you should have displayed a list of
all registered users on that page. But it was only a temporary function:
the system is not supposed to reveal such information. Instead, you will
now create a smart page which will display, for the beginning, the
screen_name and e_mail of the currently logged user.

This exercise consists of three smaller tasks:

  1. In the User controller, index action, find the currently logged
    user in the database.
  2. Using the information prepared in the previous step, display the
    information in the corresponding template.
  3. Now, modify the main menu of our application. We want the new User
    Hub page to substitute the Home Page (site/index) when anyone is logged.
    So:
    * If nobody is logged, the Home option should link to
    site/index, as it does so far.
    * If there is a logged user, the same Home option should link
    to user/index, and display the User Hub Page.

My user_conttroller.rb file looks like the following:
class UserController < ApplicationController

def register
@title = “Register”
if request.post?
@user = User.new(params[:user])
if @user.save
session[:user_id] = @user.id
flash[:notice] = "User with login #

{@user.screen_name} created successfully!"
redirect_to :action => :index
end
end
end

def index
@title = “Temporary View”
@users = User.find(:all)
@user = User.find_by_id(session[:user_id])
end

end

My Index.html.rb file looks like:

Users

    Currently Logged on User: <%=

    @user.screen_name %>

    Currently Logged on User's email: <%=

    @user.e_mail %>

Thanks for all your help in advance.

Cheers
K

Hint: if you need to break the session, or erase the session variable,
just switch your browser off and then on again. All session data will be
then nil.

Kirpal Sachdev wrote:

I have the following questions:

That’s homework, right?

The rules are, you have to make an attempt, and post part of it, with
your
question about it. Don’t just copy in your assignment verbatim!

(Also, your professor is doubtless teaching you to unit test as you go,
right?)