Getting the user name

Hi I am new to ruby and trying to obtain the user name in the login
index.rhtml where I could display “You have logged in [user name]”

How could I do this? I have been trying different options after reading
the ruby manual but still throw an error.

please help

woow wrote:

Hi I am new to ruby and trying to obtain the user name in the login
index.rhtml where I could display “You have logged in [user name]”

How could I do this? I have been trying different options after reading
the ruby manual but still throw an error.

please help

Can you post some of the things you’ve tried ? How did you get the user
name that you’re trying to display?

Alan

Alan F. wrote:

Can you post some of the things you’ve tried ? How did you get the user
name that you’re trying to display?

Alan

<%= error_messages_for ‘user’ %>

You have logged in !!
<% user = User.find(params[:name]) %>
<% user.name %>

Thats what I’ve got but I might be doing some stupid mistake. I am kinda
lost in this.

“woow” [email protected] wrote in message
news:[email protected]

<% user.name %>

try <%= user.name %>,

<% %> just processes the ruby, <%= %> will process it and output the
result

Alan B. wrote:

“woow” [email protected] wrote in message
news:[email protected]
try <%= user.name %>,

<% %> just processes the ruby, <%= %> will process it and output the
result

yeah I believe I tried that before. I did try it again and now it throws
this error…

“Couldn’t find User without an ID”

Thank you for your help.

“woow” [email protected] wrote in message

“Couldn’t find User without an ID”

sorry, I overlooked that. User.find expects a numeric record ID. Try
this
instead:
User.find_by_name(params[:name])

Alan B. wrote:

“woow” [email protected] wrote in message

“Couldn’t find User without an ID”

sorry, I overlooked that. User.find expects a numeric record ID. Try
this
instead:
User.find_by_name(params[:name])

Again the same situation with the same error? Hmmm …

Hopefully this will give more info about whats going on…

This is my login_controller.rb

def login
session[:user_id] = nil
if request.post?
user = User.authenticate(params[:name], params[:password])
if user
session[:user_id] = user.id
redirect_to(session[:original_uri] || { :action => “index” })
else
flash[:notice] = “Invalid user/password combination”
end
end
end

def logout
reset_session
flash[:notice] = “Logged out”
redirect_to(:action => “login” )
end

def index
@all_users = User.find_by_name(params[:name])
end

fallowing is my index.rhtml

<%= error_messages_for ‘user’ %>

You have logged in !!
<% for user in @all_users %>
<%= user.name %>
<% end %>

now in the controller if I do

def index
@all_users = User.find_by_name(:all)
end

it prints all the user names but how could I make it to print the logged
in user name only?

login_controller.rb:
def index
@user = User.find(session[:user_id])
end

index.rhtml:
<%= @user.name %>

On 7/17/06, woow [email protected] wrote:

    redirect_to(session[:original_uri] || { :action => "index" })

end
You have logged in !!

it prints all the user names but how could I make it to print the logged
in user name only?


Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Rick Martinez
Director of Technology
Complexity Gaming

Rick Martinez wrote:

login_controller.rb:
def index
@user = User.find(session[:user_id])
end

index.rhtml:
<%= @user.name %>

Thx so much it worked…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs