woow
July 17, 2006, 5:22pm
1
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
July 17, 2006, 5:24pm
2
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
woow
July 17, 2006, 5:27pm
3
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
July 17, 2006, 5:55pm
4
“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
woow
July 17, 2006, 6:05pm
5
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
July 17, 2006, 6:41pm
6
“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])
woow
July 17, 2006, 8:48pm
7
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 …
woow
July 17, 2006, 10:39pm
8
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?
woow
July 18, 2006, 7:14am
9
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