E
E
Eugene Burmakin2014-04-08 23:01:55
Algorithms
Eugene Burmakin, 2014-04-08 23:01:55

How to link between records in db and session id in Rails?

There is a need to associate each entry in the database with a specific visitor. But there is a nuance: no registration is provided. That is, I imagine it like this:
The visitor enters the page, session id is assigned to him. We write this value to cookies, and when the visitor creates a record (it is created by a simple click on the button), we write the data to the database table in the following form: session_id | some_data
Actually, the idea is that the user can see the data he created on the page when he re-enters. And they would be pulled to the page from the database by session_id, which is stored in cookies.
I hope I didn't explain too badly.
So here's the problem: I don't even have a close idea of ​​how to implement this in code, because I'm still far from a pro in Rails. Tell me, who can, please? Maybe I made the algorithm wrong?
Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cepega, 2014-04-08
@Cepega

Rails automatically creates a session for every visitor to the site. You can simply write the IDs of the user's records from the database into it. And then read them from there.
The user session is accessed from the controller using the session.
Here is more details

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question