Clearly I have the session and can see that session[:user_id] = 7 Now I want to use the results of this...in a page...so I am trying to use the instance variable @sess_user and at the top of the application controller, I have either... @sess_user = User.find([:first, "id = ?", session[:user_id]) or @sess_user = User.find([:first, "id = ?", session[:user_id]) gives me an error...symbol as Array index Clues? Craig
Hi, @sess_user = User.find(:first, :conditions=>["id = ?", session[:user_id]) Eric Craig White wrote:> Clearly I have the session and can see that session[:user_id] = 7 > > Now I want to use the results of this...in a page...so I am trying to > use the instance variable > > @sess_user > > and at the top of the application controller, I have either... > > @sess_user = User.find([:first, "id = ?", session[:user_id]) > or > @sess_user = User.find([:first, "id = ?", session[:user_id]) > > gives me an error...symbol as Array index > > Clues? > > Craig > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Eric Goodwin http://www.ericgoodwin.com
On Feb 15, 2006, at 4:33 PM, Craig White wrote:> Clearly I have the session and can see that session[:user_id] = 7 > > Now I want to use the results of this...in a page...so I am trying to > use the instance variable > > @sess_user > > and at the top of the application controller, I have either... > > @sess_user = User.find([:first, "id = ?", session[:user_id]) > or > @sess_user = User.find([:first, "id = ?", session[:user_id]) > > gives me an error...symbol as Array indexYou don''t need the [] around the arguments in find...and there''s a shortcut that you don''t know about. @sess_user = User.find(session[:user_id]) -- -- Tom Mornini
On Feb 15, 2006, at 4:39 PM, Tom Mornini wrote:> On Feb 15, 2006, at 4:33 PM, Craig White wrote: > >> Clearly I have the session and can see that session[:user_id] = 7 >> >> Now I want to use the results of this...in a page...so I am trying to >> use the instance variable >> >> @sess_user >> >> and at the top of the application controller, I have either... >> >> @sess_user = User.find([:first, "id = ?", session[:user_id]) >> or >> @sess_user = User.find([:first, "id = ?", session[:user_id]) >> >> gives me an error...symbol as Array index > > You don''t need the [] around the arguments in find...and there''s > a shortcut that you don''t know about.Correction: You have the [ in the wrong place. Needs to be after the comma. Short form is better still... -- -- Tom Mornini
Yeah...I got brackets out of whack... @sess_user = User.find(:first, :conditions => ["id = ?", session[:user_id] ]) or @sess_user = User.find(session[:user_id]) both still return the same error... symbol as array index which probably still isn''t what I want to get out of it since I actually want user.name from the ''find'' but nevertheless...the error is still the same. Thanks Craig On Wed, 2006-02-15 at 16:40 -0800, Eric Goodwin wrote:> Hi, > > @sess_user = User.find(:first, :conditions=>["id = ?", session[:user_id]) > > Eric > > Craig White wrote: > > Clearly I have the session and can see that session[:user_id] = 7 > > > > Now I want to use the results of this...in a page...so I am trying to > > use the instance variable > > > > @sess_user > > > > and at the top of the application controller, I have either... > > > > @sess_user = User.find([:first, "id = ?", session[:user_id]) > > or > > @sess_user = User.find([:first, "id = ?", session[:user_id]) > > > > gives me an error...symbol as Array index > > > > Clues? > > > > Craig > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >
Craig, Can you show us the exact contents of your session, or show us the code for the user id being added to the session data? It sounds like there is a problem with session[:user_id] Estelle. On 2/15/06, Craig White <craigwhite@azapple.com> wrote:> Yeah...I got brackets out of whack... > > @sess_user = User.find(:first, > :conditions => ["id = ?", session[:user_id] ]) > > or > > @sess_user = User.find(session[:user_id]) > > both still return the same error... > > symbol as array index > > which probably still isn''t what I want to get out of it since I actually > want user.name from the ''find'' but nevertheless...the error is still the > same. > > Thanks > > Craig > > On Wed, 2006-02-15 at 16:40 -0800, Eric Goodwin wrote: > > Hi, > > > > @sess_user = User.find(:first, :conditions=>["id = ?", session[:user_id]) > > > > Eric > > > > Craig White wrote: > > > Clearly I have the session and can see that session[:user_id] = 7 > > > > > > Now I want to use the results of this...in a page...so I am trying to > > > use the instance variable > > > > > > @sess_user > > > > > > and at the top of the application controller, I have either... > > > > > > @sess_user = User.find([:first, "id = ?", session[:user_id]) > > > or > > > @sess_user = User.find([:first, "id = ?", session[:user_id]) > > > > > > gives me an error...symbol as Array index > > > > > > Clues? > > > > > > Craig > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Wed, 2006-02-15 at 17:34 -0800, Estelle Winterflood wrote:> Craig, > > Can you show us the exact contents of your session, or show us the > code for the user id being added to the session data? It sounds like > there is a problem with session[:user_id] >---- I''m ashamed to tell you that I solved it entirely differently. When I create the session, I get all the session variables I will need later rather than resorting to having to get them out of the db later. This is a simple process and it was my twisted logic that said...OK, I need this value now and the only way I can get it is from the user_id in the session. Much simpler - thanks for the concern. I am now onto rights based roles and I can see that Chad''s ''Recipes'' is gonna pay me dividends now. Thanks Craig