I am working in an application that uses Rails. I need to be able to set a variable for each user called language. Currently I do this through a ruby session variable that I setup in the controller, but when a user closes their browser I lose their language variable and they have to set it again every time they login. I need to attach this data to the user somehow. I have to use Ruby and Javascript on the front end and I can only make requests for data via Ruby.
<script type="text/javascript">
var language=getCookie(“language”);
//***HELP use ajax to set user language preference in ruby***
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
</script>
<% use language variable here to request data in ruby %>
In ruby, by default, cookies only last till the session is closed. You can override that by just giving them an expiration date. Which means they'll last even if the user closes the browser, until they reach that expiration date, Just set it arbitrarily high and you'll be good to go.