Setting global variables in my js file doesn’t seem to work. How can I set rails session variables from JavaScript?
I’d like a solution that doesn’t use jQuery.
Edit: The solution is to use an HTML form containing hidden fields.
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.
Global variables only live for the duration of a page view. Once the page is rerendered, they are reset to what their default values are.
If you need to keep the values, you need to use cookies or local storage. Other option is to submit them to the server with Ajax and have the server remember them and set the values when the page is rendered.