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.
Solution: Controllers - Ruby on Rails Tutorial
From the course: Ruby on Rails 6: Controllers and Views
Solution: Controllers
(upbeat music) - [Instructor] Hopefully you were able to use what you've learned about the features inside Rails controllers to complete the challenge assignment. If not, or if you just want to check your work against mine, I'll show you the solution that I came up. The first task was to record a note in the log file every time a user logs out. So that's going to be in the access_controller and right down here in the destroy action, you see I've got logger.info. And I'm logging out the user and I'm going ahead and just putting in whatever their session ID was so that I have some kind of identifier to let me know who logged out. I also modified the login action to work the same way. So now we'll have a record in our log file when a user logs in or when they log out. The second task was to set username automatically for every controller in the app. You may remember that we already had set_username as a method and we…
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)
-
-
-
-