Forum: Ruby on Rails Different views for different conditions

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Kirpal S. (Guest)
on 2009-04-06 17:15
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.
          * 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"
      @user =[:user])
session[:user_id] =
        flash[:notice] = "User with login #

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

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


My Index.html.rb file looks like:

<p>Currently Logged on User: <%=

@user.screen_name %></p>
<p>Currently Logged on User's email: <%=

@user.e_mail %></p>

Thanks for all your help in advance.


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.
Phlip (Guest)
on 2009-04-06 18:43
(Received via mailing list)
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
question about it. Don't just copy in your assignment verbatim!

(Also, your professor is doubtless teaching you to unit test as you go,
This topic is locked and can not be replied to.