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 %>