Forgive my ignorance ya''ll. I''m trying to extract a username
from a
table using the user id.
I''ve tried:
@authenticated_user = User.find(:first, :select => "login",
:conditions
=> "id = ''1''")
AND:
@authenticated_user = User.find_by_sql("select login from users where
id=''1''")
within an action that corresponds to a view that has <%@authenticated_user
%>, and all I get for output is:
#
What gives?
My end goal is to grab the user''s id from session[:user_id], and use it
to look up their username in the users database.
Please tell me the best way to do this.
-frivolivolous
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
> <%= @authenticated_user %>How about <%= @authenticated_user.login %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 8/31/06, frivolivolous <jstepper-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Forgive my ignorance ya''ll. I''m trying to extract a username from a > table using the user id. > > I''ve tried: > @authenticated_user = User.find(:first, :select => "login", :conditions > => "id = ''1''") > AND: > @authenticated_user = User.find_by_sql("select login from users where > id=''1''") > > within an action that corresponds to a view that has <%> @authenticated_user %>, and all I get for output is: > #If you look at the html page source, you''ll find that the output is actually #<User:0x0290483> - the browser does not display the <...> stuff. What the ActiveRecord find method returns you if you give it a select statement explicitly is an object instance of the model class, with the fields in the select statement. So @authenticated_user.login will work. I don''t see a reason though why you can''t pull the whole user out of the database - why do you only want the login field? There''s a lot more typing involved, which means it''s almost certainly wrong ;) Cheers, Max --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Try...
@authenticated_user = User.find(1) # or your SQL find, without the :select
<%= @authenticated_user.login %>
HTH,
Nathan
-----Original Message-----
From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
[mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org]On Behalf Of
frivolivolous
Sent: Wednesday, August 30, 2006 4:46 PM
To: Ruby on Rails: Talk
Subject: [Rails] extracting username
Forgive my ignorance ya''ll. I''m trying to extract a username
from a
table using the user id.
I''ve tried:
@authenticated_user = User.find(:first, :select => "login",
:conditions
=> "id = ''1''")
AND:
@authenticated_user = User.find_by_sql("select login from users where
id=''1''")
within an action that corresponds to a view that has <%@authenticated_user
%>, and all I get for output is:
#
What gives?
My end goal is to grab the user''s id from session[:user_id], and use it
to look up their username in the users database.
Please tell me the best way to do this.
-frivolivolous
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---