From the course: Ruby on Rails 6: Controllers and Views

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Store data in sessions

Store data in sessions - Ruby on Rails Tutorial

From the course: Ruby on Rails 6: Controllers and Views

Start my 1-month free trial

Store data in sessions

- [Narrator] Now that we understand cookies, we're ready to talk about sessions. Sessions work a lot like cookies. The classic way that sessions work is that the web server sends a session ID to the browser, which then saves it in a cookie. Then the browser sends that session identifier with each and every future request back to the web server, just like a cookie. But then what's different is the web server uses that session identifier to locate a session file on the server. And that allows more data to be stored and also stores the data server side where its contents can't be read or altered. Now that's not the only way to do it, but that's the classic approach. To use sessions in Rails, it's just as easy as using cookies, where before we called cookies, now we call session. When you want to set a value in your controller, you would call session and then in square brackets, you would put the key that you want to…

Contents