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
<%= @authenticated_user %>
How about <%= @authenticated_user.login %>
On 8/31/06, frivolivolous [email protected] wrote:
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