I’m learning how to work with cookies in Ruby on Rails. All I know is how to set the name and the value of a cookie, but I want to store up to three more fields. So any hints or good tutorials would be appreciated!
Thanks for any help.
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.
Cookies by definition consist of a single name / value pair, where both fields are text. You should really be using three separate cookies to store separate values.
If for some reason you can’t or don’t want to have more than one cookie, you can put different values joined with a separator (an arbitrary text like
~~in the following example):But that way, you’ll have to parse the cookie back, retrieving values by splitting the cookie value using your separator text. There’s danger however that one day a proper value will contain your separator and ruin the parsing process.