Forum: Ruby on Rails Different views for different conditions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E1406ccf0c95473d0a75ade0d145c413?d=identicon&s=25 Kirpal Sachdev (kirps)
on 2009-04-06 15: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.
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:

<h1>Users</h1>
<ol>
<p>Currently Logged on User: <%=

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

@user.e_mail %></p>
</ol>

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.
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-04-06 16: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
_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?)
This topic is locked and can not be replied to.