Is there a way to concatenate a number onto a string and use that string in a session variable? I tried something like.. x = 1 session["user" + x] = user one but nothing happen unless I use the session[:user] syntax. Is there a way around this so I can set the session[:user + x] variable? Thanks in advance -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
Chris Hickman wrote:> Is there a way to concatenate a number onto a string and use that string > in a session variable? I tried something like.. > > x = 1 > session["user" + x] = user one > > but nothing happen unless I use the session[:user] syntax. Is there a > way around this so I can set the session[:user + x] variable? > > Thanks in advance >session["user#{x}".to_sym] FYI, it''s generally not recommended to store whole objects in the session. It''s much better to store just the ID and retrieve the object from the database when you need it. session[:user_id] = @user.id then in future page views User.find(session[:user_id]) -- http://www.5valleys.com/ http://www.workingwithrails.com/person/8078 --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
> > FYI, it''s generally not recommended to store whole objects in the > session. It''s much better to store just the ID and retrieve the object > from the database when you need it. >Thanks a lot. I am not using it for a whole object. I tried to make the example as simple as possible. Thanks for the advice though. -- 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?hl=en -~----------~----~----~----~------~----~------~--~---