Currently I have a session variable that returns the same value when I use both session["test"] or session[:test]. Are these two the same? Is it better to use one over the other?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In a standard Ruby Hash they’re not the same (string vs symbol)
However, the rails
SessionHashsubclass callsto_son the keys before storing them, so all keys are stored as strings (even if you specify a symbol):That’s why
session[:test]andsession["test"]will return the same value in rails.