Markus
Markus

Reputation: 2564

Rails way to store data on client for long periods

What is the preferred way to store some data on the users computer for long periods of time. I am unsure how long a session lives. As an alternative I could store the data in a cookie, but here I can't find any high level storing API which also takes care of signing my data and make sure it is not tampered with.

How do you typically solve this problem of having a persistent user id between sessions.

Upvotes: 1

Views: 366

Answers (2)

Dave Newton
Dave Newton

Reputation: 160241

You handle a persistent user with a cookie--but you are quite limited in how much data you can store in a cookie (4K?).

Large sessions should be stored on the database. Some browsers support local storage (HTML5) which may also be an option.

If you want to guarantee it can't be tampered with outside of your application, you should store it on the server-side in a DB. The signed cookies make tampering difficult (or at least detectable), but you're still size-contrained.

Upvotes: 2

Related Questions