# Different views for different conditions

**URL:** <https://www.ruby-forum.com/t/different-views-for-different-conditions/164842>\
**Category:** Rails\
**Created:** [April 6, 2009, 3:15pm UTC](https://www.ruby-forum.com/t/different-views-for-different-conditions/164842 "2009-04-06T15:15:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kirps](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a6a055/32.png) [@kirps](https://www.ruby-forum.com/u/kirps)\
**Post date:** [April 6, 2009, 3:15pm UTC](https://www.ruby-forum.com/t/different-views-for-different-conditions/164842/1 "2009-04-06T15:15:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kirps](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a6a055/32.png) [@kirps](https://www.ruby-forum.com/u/kirps)\
**Post date:** [April 6, 2009, 4:43pm UTC](https://www.ruby-forum.com/t/different-views-for-different-conditions/164842/2 "2009-04-06T16:43:29Z")

</div>

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?)
