I'm trying to save a variable called persistent_data
.
I usually use session[:persistent_data]
or cookies[:persistent_data]
, but I would like to use the localstorage instead.
How do I do that on Rails?
Localstorage has nothing to do with rails. You do it the same way as with any other language:
<script>
localStorage.setItem("company_id", "1");
</script>
localStorage.getItem("company_id");
=> 1
You can use rails to dynamically set the item however:
<script>
localStorage.setItem("company_id", "<%= @company.id %>");
</script>