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 - Ruby on Rails Tutorial
From the course: Ruby on Rails 6: Controllers and Views
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
(Locked)
Store data in cookies7m 32s
-
(Locked)
Store data in sessions7m 55s
-
Messaging with the flash hash4m 2s
-
(Locked)
Log information to a file7m 44s
-
(Locked)
Inherit common behaviors with ApplicationController6m 28s
-
(Locked)
Use filters to call methods automatically7m
-
(Locked)
Understanding CSRF protections4m 30s
-
(Locked)
Challenge: Controllers1m 36s
-
(Locked)
Solution: Controllers3m 19s
-
(Locked)
-
-
-
-